Merge "Add uid data even though on battery stats" into oc-mr1-dev
diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java
index 3d7c5b6..1bda130 100644
--- a/src/com/android/settings/bluetooth/BluetoothEnabler.java
+++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java
@@ -210,12 +210,7 @@
      */
     @VisibleForTesting
     boolean maybeEnforceRestrictions() {
-        EnforcedAdmin admin = mRestrictionUtils.checkIfRestrictionEnforced(
-                mContext, UserManager.DISALLOW_BLUETOOTH);
-        if (admin == null) {
-            admin = mRestrictionUtils.checkIfRestrictionEnforced(
-                    mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH);
-        }
+        EnforcedAdmin admin = getEnforcedAdmin(mRestrictionUtils, mContext);
         mSwitchWidget.setDisabledByAdmin(admin);
         if (admin != null) {
             mSwitchWidget.setChecked(false);
@@ -227,4 +222,15 @@
         return admin != null;
     }
 
+    public static EnforcedAdmin getEnforcedAdmin(RestrictionUtils mRestrictionUtils,
+            Context mContext) {
+        EnforcedAdmin admin = mRestrictionUtils.checkIfRestrictionEnforced(
+                mContext, UserManager.DISALLOW_BLUETOOTH);
+        if (admin == null) {
+            admin = mRestrictionUtils.checkIfRestrictionEnforced(
+                    mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH);
+        }
+        return admin;
+    }
+
 }
diff --git a/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java b/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java
index b0e34fa..fc746b9 100644
--- a/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java
+++ b/src/com/android/settings/fuelgauge/anomaly/action/LocationCheckAction.java
@@ -49,7 +49,9 @@
     public void handlePositiveAction(Anomaly anomaly, int contextMetricsKey) {
         super.handlePositiveAction(anomaly, contextMetricsKey);
         mRuntimePermissionPresenter.revokeRuntimePermission(anomaly.packageName,
-                Manifest.permission_group.LOCATION);
+                Manifest.permission.ACCESS_COARSE_LOCATION);
+        mRuntimePermissionPresenter.revokeRuntimePermission(anomaly.packageName,
+                Manifest.permission.ACCESS_FINE_LOCATION);
     }
 
     @Override
diff --git a/src/com/android/settings/network/TetherPreferenceController.java b/src/com/android/settings/network/TetherPreferenceController.java
index 5712907..1c9959e 100644
--- a/src/com/android/settings/network/TetherPreferenceController.java
+++ b/src/com/android/settings/network/TetherPreferenceController.java
@@ -88,8 +88,7 @@
     public TetherPreferenceController(Context context, Lifecycle lifecycle) {
         super(context);
         mBluetoothPan = new AtomicReference<>();
-        mAdminDisallowedTetherConfig = checkIfRestrictionEnforced(
-                mContext, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
+        mAdminDisallowedTetherConfig = isTetherConfigDisallowed(context);
         mConnectivityManager =
                 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -170,6 +169,11 @@
         }
     }
 
+    public static boolean isTetherConfigDisallowed(Context context) {
+        return checkIfRestrictionEnforced(
+                context, DISALLOW_CONFIG_TETHERING, UserHandle.myUserId()) != null;
+    }
+
     @VisibleForTesting
     void updateSummary() {
         if (mPreference == null) {
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 78b763c..3849882 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -35,8 +35,10 @@
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.app.admin.DevicePolicyManager;
+import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
@@ -108,6 +110,8 @@
     protected NotificationBackend.AppRow mAppRow;
     protected boolean mShowLegacyChannelConfig = false;
 
+    protected boolean mListeningToPackageRemove;
+
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
@@ -159,6 +163,13 @@
         }
 
         mUserId = UserHandle.getUserId(mUid);
+        startListeningToPackageRemove();
+    }
+
+    @Override
+    public void onDestroy() {
+        stopListeningToPackageRemove();
+        super.onDestroy();
     }
 
     @Override
@@ -456,4 +467,38 @@
         return channel.isBlockableSystem()
                 || channel.getImportance() == NotificationManager.IMPORTANCE_NONE;
     }
+
+    protected void startListeningToPackageRemove() {
+        if (mListeningToPackageRemove) {
+            return;
+        }
+        mListeningToPackageRemove = true;
+        final IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_REMOVED);
+        filter.addDataScheme("package");
+        getContext().registerReceiver(mPackageRemovedReceiver, filter);
+    }
+
+    protected void stopListeningToPackageRemove() {
+        if (!mListeningToPackageRemove) {
+            return;
+        }
+        mListeningToPackageRemove = false;
+        getContext().unregisterReceiver(mPackageRemovedReceiver);
+    }
+
+    protected void onPackageRemoved() {
+        getActivity().finishAndRemoveTask();
+    }
+
+    protected final BroadcastReceiver mPackageRemovedReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            String packageName = intent.getData().getSchemeSpecificPart();
+            if (mPkgInfo == null || TextUtils.equals(mPkgInfo.packageName, packageName)) {
+                if (DEBUG) Log.d(TAG, "Package (" + packageName + ") removed. Removing"
+                        + "NotificationSettingsBase.");
+                onPackageRemoved();
+            }
+        }
+    };
 }
diff --git a/src/com/android/settings/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 1aabe5c..5a3d426 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -851,7 +851,7 @@
             mEapIdentityView = (TextView) mView.findViewById(R.id.identity);
             mEapAnonymousView = (TextView) mView.findViewById(R.id.anonymous);
 
-            if (mAccessPoint.isCarrierAp()) {
+            if (mAccessPoint != null && mAccessPoint.isCarrierAp()) {
                 mEapMethodSpinner.setSelection(mAccessPoint.getCarrierApEapType());
             }
 
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictionUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictionUtils.java
new file mode 100644
index 0000000..f39f10f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowRestrictionUtils.java
@@ -0,0 +1,24 @@
+package com.android.settings.testutils.shadow;
+
+import android.content.Context;
+import com.android.settings.bluetooth.RestrictionUtils;
+import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@Implements(RestrictionUtils.class)
+public class ShadowRestrictionUtils {
+    private static boolean isRestricted = false;
+
+    @Implementation
+    public EnforcedAdmin checkIfRestrictionEnforced(Context context, String restriction) {
+        if (isRestricted) {
+            return new EnforcedAdmin();
+        }
+        return null;
+    }
+
+    public static void setRestricted(boolean restricted) {
+        isRestricted = restricted;
+    }
+}