Merge "Bug 21589105 Rescope SYSTEM_ALERT_WINDOW (UX and Settings app change)..." into mnc-dev

This commit is contained in:
Billy Lau
2015-07-17 18:28:27 +00:00
committed by Android (Google) Code Review
5 changed files with 38 additions and 48 deletions

View File

@@ -2537,6 +2537,8 @@
<action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" /> <action android:name="android.settings.action.MANAGE_OVERLAY_PERMISSION" />
<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>
<activity android:name="Settings$WriteSettingsActivity" <activity android:name="Settings$WriteSettingsActivity"

View File

@@ -6849,8 +6849,8 @@
<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=30] --> <!-- Title of Draw Overlay preference item [CHAR LIMIT=45] -->
<string name="draw_overlay_title">Apps that can draw overlay</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>
<!-- Settings title in main settings screen for SYSTEM_ALERT_WINDOW [CHAR LIMIT=45] --> <!-- Settings title in main settings screen for SYSTEM_ALERT_WINDOW [CHAR LIMIT=45] -->
@@ -6858,9 +6858,9 @@
<!-- Title for the apps with SYSTEM_ALERT_WINDOW permission/privilege [CHAR LIMIT=20] --> <!-- Title for the apps with SYSTEM_ALERT_WINDOW permission/privilege [CHAR LIMIT=20] -->
<string name="system_alert_window_apps_title">Apps</string> <string name="system_alert_window_apps_title">Apps</string>
<!-- Title for the apps that are allowed to draw on top of other apps [CHAR LIMIT=60] --> <!-- Title for the apps that are allowed to draw on top of other apps [CHAR LIMIT=60] -->
<string name="system_alert_window_access_title">Can draw overlays</string> <string name="system_alert_window_access_title">Draw over other apps</string>
<!-- Label for setting which controls whether app can draw overlays [CHAR LIMIT=45] --> <!-- Label for setting which controls whether app can draw overlays [CHAR LIMIT=45] -->
<string name="permit_draw_overlay">Permit drawing overlays</string> <string name="permit_draw_overlay">Permit drawing over other apps</string>
<!-- Link to the apps page for SYSTEM_ALERT_WINDOW settings [CHAR LIMIT=45] --> <!-- Link to the apps page for SYSTEM_ALERT_WINDOW settings [CHAR LIMIT=45] -->
<string name="app_overlay_permission_preference">App draw on top permission</string> <string name="app_overlay_permission_preference">App draw on top permission</string>
<!-- Description of allowing overlay setting [CHAR LIMIT=NONE] --> <!-- Description of allowing overlay setting [CHAR LIMIT=NONE] -->
@@ -6868,8 +6868,8 @@
<!-- Keyword for SYSTEM_ALERT_WINDOW --> <!-- Keyword for SYSTEM_ALERT_WINDOW -->
<string name="keywords_system_alert_window">system alert window dialog draw on top other apps</string> <string name="keywords_system_alert_window">system alert window dialog draw on top other apps</string>
<!-- Main settings screen item's title to go into the overlay settings screen [CHAR LIMIT=25] --> <!-- Main settings screen item's title to go into the overlay settings screen [CHAR LIMIT=30] -->
<string name="overlay_settings">Overlay settings</string> <string name="overlay_settings">Draw over other apps</string>
<!-- Summary of number of apps currently can draw overlays [CHAR LIMIT=60] --> <!-- Summary of number of apps currently can draw overlays [CHAR LIMIT=60] -->
<string name="system_alert_window_summary"><xliff:g id="count" example="10">%d</xliff:g> of <xliff:g id="count" example="10">%d</xliff:g> apps allowed to draw on top of other apps</string> <string name="system_alert_window_summary"><xliff:g id="count" example="10">%d</xliff:g> of <xliff:g id="count" example="10">%d</xliff:g> apps allowed to draw on top of other apps</string>
@@ -6894,9 +6894,9 @@
<string name="filter_write_settings_apps">Can write system settings</string> <string name="filter_write_settings_apps">Can write system settings</string>
<!-- Title for the apps that are allowed to write system settings [CHAR LIMIT=60] --> <!-- Title for the apps that are allowed to write system settings [CHAR LIMIT=60] -->
<string name="write_settings_title">Can write system settings</string> <string name="write_settings_title">Can write system settings</string>
<!-- Main settings screen item's title to go into the write system settings screen [CHAR LIMIT=25] --> <!-- Main settings screen item's title to go into the write system settings screen [CHAR LIMIT=30] -->
<string name="write_system_settings">Write system settings</string> <string name="write_system_settings">Write system settings</string>
<!-- Link to the apps page for WRITE_SETTINGS settings [CHAR LIMIT=45] --> <!-- Link to the apps page for WRITE_SETTINGS settings [CHAR LIMIT=52] -->
<string name="write_settings_preference">App write system settings permission</string> <string name="write_settings_preference">App write system settings permission</string>
<!-- Label for setting which controls whether app can write system settings [CHAR LIMIT=45] --> <!-- Label for setting which controls whether app can write system settings [CHAR LIMIT=45] -->
<string name="permit_write_settings">Allow write system settings</string> <string name="permit_write_settings">Allow write system settings</string>

View File

@@ -59,15 +59,13 @@ public class AppStateOverlayBridge extends AppStateAppOpsBridge {
return super.getNumPackagesAllowedByAppOps(); return super.getNumPackagesAllowedByAppOps();
} }
public static class OverlayState { public static class OverlayState extends AppStateAppOpsBridge.PermissionState {
PermissionState mPermissionState;
public OverlayState(PermissionState permissionState) { public OverlayState(PermissionState permissionState) {
mPermissionState = permissionState; super(permissionState.packageName, permissionState.userHandle);
} this.packageInfo = permissionState.packageInfo;
this.appOpMode = permissionState.appOpMode;
public boolean isAllowed() { this.permissionDeclared = permissionState.permissionDeclared;
return mPermissionState.isPermissible();
} }
} }

View File

@@ -22,8 +22,8 @@ import android.content.ComponentName;
import android.content.Context; 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.PackageInfo;
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 +36,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.AppStateOverlayBridge.OverlayState; import com.android.settings.applications.AppStateOverlayBridge.OverlayState;
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;
@@ -99,7 +100,7 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
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 app draw overlay settings " + mSettingsIntent, e); Log.w(LOG_TAG, "Unable to launch app draw overlay settings " + mSettingsIntent, e);
} }
} }
return true; return true;
@@ -110,8 +111,8 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference == mSwitchPref) { if (preference == mSwitchPref) {
if (mOverlayState != null && (Boolean) newValue != mOverlayState.isAllowed()) { if (mOverlayState != null && (Boolean) newValue != mOverlayState.isPermissible()) {
setCanDrawOverlay(!mOverlayState.isAllowed()); setCanDrawOverlay(!mOverlayState.isPermissible());
refreshUi(); refreshUi();
} }
return true; return true;
@@ -123,7 +124,6 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
mAppOpsManager.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW, mAppOpsManager.setMode(AppOpsManager.OP_SYSTEM_ALERT_WINDOW,
mPackageInfo.applicationInfo.uid, mPackageName, newState mPackageInfo.applicationInfo.uid, mPackageName, newState
? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED); ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
canDrawOverlay(mPackageName);
} }
private boolean canDrawOverlay(String pkgName) { private boolean canDrawOverlay(String pkgName) {
@@ -141,17 +141,10 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
mOverlayState = mOverlayBridge.getOverlayInfo(mPackageName, mOverlayState = mOverlayBridge.getOverlayInfo(mPackageName,
mPackageInfo.applicationInfo.uid); mPackageInfo.applicationInfo.uid);
boolean isAllowed = mOverlayState.isAllowed(); boolean isAllowed = mOverlayState.isPermissible();
mSwitchPref.setChecked(isAllowed); mSwitchPref.setChecked(isAllowed);
mOverlayPrefs.setEnabled(isAllowed); mOverlayPrefs.setEnabled(isAllowed);
getPreferenceScreen().removePreference(mOverlayPrefs);
ResolveInfo resolveInfo = mPm.resolveActivityAsUser(mSettingsIntent,
PackageManager.GET_META_DATA, mUserId);
if (resolveInfo == null) {
if (findPreference(KEY_APP_OPS_SETTINGS_PREFS) != null) {
getPreferenceScreen().removePreference(mOverlayPrefs);
}
}
return true; return true;
} }
@@ -167,40 +160,38 @@ public class DrawOverlayDetails extends AppInfoWithHeader implements OnPreferenc
} }
public static CharSequence getSummary(Context context, AppEntry entry) { public static CharSequence getSummary(Context context, AppEntry entry) {
if (entry.extraInfo != null) {
return getSummary(context, new OverlayState((PermissionState)entry.extraInfo));
}
// fallback if for whatever reason entry.extrainfo is null - the result
// may be less accurate
return getSummary(context, entry.info.packageName); return getSummary(context, entry.info.packageName);
} }
public static CharSequence getSummary(Context context, OverlayState overlayState) {
return context.getString(overlayState.isPermissible() ?
R.string.system_alert_window_on : R.string.system_alert_window_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;
PackageManager packageManager = context.getPackageManager(); PackageManager packageManager = context.getPackageManager();
int uid = -1;
try { try {
ApplicationInfo appInfo = packageManager.getApplicationInfo(pkg, 0); ApplicationInfo appInfo = packageManager.getApplicationInfo(pkg, 0);
uid = appInfo.uid;
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
isSystem = true; return context.getString(R.string.system_alert_window_on);
} }
} 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.system_alert_window_off);
} }
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context
.APP_OPS_SERVICE); .APP_OPS_SERVICE);
List<AppOpsManager.PackageOps> packageOps = appOpsManager.getPackagesForOps(
APP_OPS_OP_CODE);
if (packageOps == null) {
return context.getString(R.string.system_alert_window_off);
}
int uid = isSystem ? 0 : -1;
for (AppOpsManager.PackageOps packageOp : packageOps) {
if (pkg.equals(packageOp.getPackageName())) {
uid = packageOp.getUid();
break;
}
}
if (uid == -1) { if (uid == -1) {
return context.getString(R.string.system_alert_window_off); return context.getString(R.string.system_alert_window_off);
} }

View File

@@ -1086,8 +1086,7 @@ public class ManageApplications extends InstrumentedFragment
break; break;
case LIST_TYPE_OVERLAY: case LIST_TYPE_OVERLAY:
holder.summary.setText(DrawOverlayDetails.getSummary(mContext, holder.summary.setText(DrawOverlayDetails.getSummary(mContext, holder.entry));
holder.entry));
break; break;
case LIST_TYPE_WRITE_SETTINGS: case LIST_TYPE_WRITE_SETTINGS: