am bc3695c2: am e267fb31: am d06ba151: Merge "Bug 21589105 Rescope WRITE_SETTINGS (UX and Settings app change)..." into mnc-dev

* commit 'bc3695c231a5a16f45059e0e561a35d49353afc5':
  Bug 21589105 Rescope WRITE_SETTINGS (UX and Settings app change)...
This commit is contained in:
Billy Lau
2015-07-21 18:21:45 +00:00
committed by Android Git Automerger
4 changed files with 30 additions and 27 deletions

View File

@@ -2548,6 +2548,8 @@
<action android:name="android.settings.action.MANAGE_WRITE_SETTINGS" /> <action android:name="android.settings.action.MANAGE_WRITE_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.applications.ManageApplications" />
</activity> </activity>
</application> </application>

View File

@@ -6868,7 +6868,7 @@
<string name="accessibility_lock_screen_progress"><xliff:g id="count" example="1">%1$d</xliff:g> of <xliff:g id="count" example="1">%2$d</xliff:g> characters used</string> <string name="accessibility_lock_screen_progress"><xliff:g id="count" example="1">%1$d</xliff:g> of <xliff:g id="count" example="1">%2$d</xliff:g> characters used</string>
<!-- System Alert Window settings --> <!-- System Alert Window settings -->
<!-- Title of Draw Overlay preference item [CHAR LIMIT=45] --> <!-- Title of Draw Overlay preference item [CHAR LIMIT=55] -->
<string name="draw_overlay_title">Apps that can draw over other apps</string> <string name="draw_overlay_title">Apps that can draw over other apps</string>
<!-- Title of draw overlay screen [CHAR LIMIT=30] --> <!-- Title of draw overlay screen [CHAR LIMIT=30] -->
<string name="draw_overlay">Draw over other apps</string> <string name="draw_overlay">Draw over other apps</string>

View File

@@ -60,15 +60,12 @@ public class AppStateWriteSettingsBridge extends AppStateAppOpsBridge {
return super.getNumPackagesAllowedByAppOps(); return super.getNumPackagesAllowedByAppOps();
} }
public static class WriteSettingsState { public static class WriteSettingsState extends AppStateAppOpsBridge.PermissionState {
PermissionState mPermissionState;
public WriteSettingsState(PermissionState permissionState) { public WriteSettingsState(PermissionState permissionState) {
mPermissionState = permissionState; super(permissionState.packageName, permissionState.userHandle);
} this.packageInfo = permissionState.packageInfo;
this.appOpMode = permissionState.appOpMode;
public boolean canWrite() { this.permissionDeclared = permissionState.permissionDeclared;
return mPermissionState.isPermissible();
} }
} }

View File

@@ -23,7 +23,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.preference.Preference; import android.preference.Preference;
@@ -36,6 +35,7 @@ import android.util.Log;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.settings.InstrumentedFragment; import com.android.settings.InstrumentedFragment;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
import com.android.settings.applications.AppStateWriteSettingsBridge.WriteSettingsState; import com.android.settings.applications.AppStateWriteSettingsBridge.WriteSettingsState;
import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry; import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -98,7 +98,7 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
try { try {
getActivity().startActivityAsUser(mSettingsIntent, new UserHandle(mUserId)); getActivity().startActivityAsUser(mSettingsIntent, new UserHandle(mUserId));
} catch (ActivityNotFoundException e) { } catch (ActivityNotFoundException e) {
Log.w(TAG, "Unable to launch write system settings " + mSettingsIntent, e); Log.w(LOG_TAG, "Unable to launch write system settings " + mSettingsIntent, e);
} }
} }
return true; return true;
@@ -109,8 +109,9 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mSwitchPref) { if (preference == mSwitchPref) {
if (mWriteSettingsState != null && (Boolean) newValue != mWriteSettingsState.canWrite()) { if (mWriteSettingsState != null && (Boolean) newValue != mWriteSettingsState
setCanWriteSettings(!mWriteSettingsState.canWrite()); .isPermissible()) {
setCanWriteSettings(!mWriteSettingsState.isPermissible());
refreshUi(); refreshUi();
} }
return true; return true;
@@ -122,7 +123,6 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
mAppOpsManager.setMode(AppOpsManager.OP_WRITE_SETTINGS, mAppOpsManager.setMode(AppOpsManager.OP_WRITE_SETTINGS,
mPackageInfo.applicationInfo.uid, mPackageName, newState mPackageInfo.applicationInfo.uid, mPackageName, newState
? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED); ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
canWriteSettings(mPackageName);
} }
private boolean canWriteSettings(String pkgName) { private boolean canWriteSettings(String pkgName) {
@@ -140,17 +140,10 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
mWriteSettingsState = mAppBridge.getWriteSettingsInfo(mPackageName, mWriteSettingsState = mAppBridge.getWriteSettingsInfo(mPackageName,
mPackageInfo.applicationInfo.uid); mPackageInfo.applicationInfo.uid);
boolean canWrite = mWriteSettingsState.canWrite(); boolean canWrite = mWriteSettingsState.isPermissible();
mSwitchPref.setChecked(canWrite); mSwitchPref.setChecked(canWrite);
mWriteSettingsPrefs.setEnabled(canWrite); mWriteSettingsPrefs.setEnabled(canWrite);
getPreferenceScreen().removePreference(mWriteSettingsPrefs);
ResolveInfo resolveInfo = mPm.resolveActivityAsUser(mSettingsIntent,
PackageManager.GET_META_DATA, mUserId);
if (resolveInfo == null) {
if (findPreference(KEY_APP_OPS_SETTINGS_PREFS) != null) {
getPreferenceScreen().removePreference(mWriteSettingsPrefs);
}
}
return true; return true;
} }
@@ -166,9 +159,20 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
} }
public static CharSequence getSummary(Context context, AppEntry entry) { public static CharSequence getSummary(Context context, AppEntry entry) {
if (entry.extraInfo != null) {
return getSummary(context, new WriteSettingsState((PermissionState)entry
.extraInfo));
}
// fallback if entry.extrainfo is null - although this should not happen
return getSummary(context, entry.info.packageName); return getSummary(context, entry.info.packageName);
} }
public static CharSequence getSummary(Context context, WriteSettingsState writeSettingsState) {
return context.getString(writeSettingsState.isPermissible() ? R.string.write_settings_on :
R.string.write_settings_off);
}
public static CharSequence getSummary(Context context, String pkg) { public static CharSequence getSummary(Context context, String pkg) {
// first check if pkg is a system pkg // first check if pkg is a system pkg
boolean isSystem = false; boolean isSystem = false;
@@ -180,8 +184,8 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
} }
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
// pkg doesn't even exist? // pkg doesn't even exist?
Log.w(TAG, "Package " + pkg + " not found", e); Log.w(LOG_TAG, "Package " + pkg + " not found", e);
return context.getString(R.string.system_alert_window_off); return context.getString(R.string.write_settings_off);
} }
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context
@@ -189,7 +193,7 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
List<AppOpsManager.PackageOps> packageOps = appOpsManager.getPackagesForOps( List<AppOpsManager.PackageOps> packageOps = appOpsManager.getPackagesForOps(
APP_OPS_OP_CODE); APP_OPS_OP_CODE);
if (packageOps == null) { if (packageOps == null) {
return context.getString(R.string.system_alert_window_off); return context.getString(R.string.write_settings_off);
} }
int uid = isSystem ? 0 : -1; int uid = isSystem ? 0 : -1;
@@ -201,7 +205,7 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
} }
if (uid == -1) { if (uid == -1) {
return context.getString(R.string.system_alert_window_off); return context.getString(R.string.write_settings_off);
} }
int mode = appOpsManager.noteOpNoThrow(AppOpsManager.OP_WRITE_SETTINGS, uid, pkg); int mode = appOpsManager.noteOpNoThrow(AppOpsManager.OP_WRITE_SETTINGS, uid, pkg);