Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bb3aa263 authored by Billy Lau's avatar Billy Lau
Browse files

Bug 21589105 Rescope WRITE_SETTINGS (UX and Settings app change)...

Overall, fixed the detection of the state of permission in the corresponding
UX to be more accurate. Also ensured that apps needing this capability can
launch the summary UX through a specific intent.

AndroidManifest:
Adds the proper intent-filter so that apps can launch the Settings page using
intent.

strings.xml:
Increased the CHAR limits for some strings due to requests from translators.

Change-Id: Ie64f86e034867ed582c1c583a5e8f84671fa4d63
parent d85fafce
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2548,6 +2548,8 @@
                <action android:name="android.settings.action.MANAGE_WRITE_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.applications.ManageApplications" />
        </activity>

    </application>
+1 −1
Original line number Diff line number Diff line
@@ -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>
    <!-- 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>
    <!-- Title of draw overlay screen [CHAR LIMIT=30] -->
    <string name="draw_overlay">Draw over other apps</string>
+5 −8
Original line number Diff line number Diff line
@@ -60,15 +60,12 @@ public class AppStateWriteSettingsBridge extends AppStateAppOpsBridge {
        return super.getNumPackagesAllowedByAppOps();
    }

    public static class WriteSettingsState {
        PermissionState mPermissionState;

    public static class WriteSettingsState extends AppStateAppOpsBridge.PermissionState {
        public WriteSettingsState(PermissionState permissionState) {
            mPermissionState = permissionState;
        }

        public boolean canWrite() {
            return mPermissionState.isPermissible();
            super(permissionState.packageName, permissionState.userHandle);
            this.packageInfo = permissionState.packageInfo;
            this.appOpMode = permissionState.appOpMode;
            this.permissionDeclared = permissionState.permissionDeclared;
        }
    }

+22 −18
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.preference.Preference;
@@ -36,6 +35,7 @@ import android.util.Log;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.InstrumentedFragment;
import com.android.settings.R;
import com.android.settings.applications.AppStateAppOpsBridge.PermissionState;
import com.android.settings.applications.AppStateWriteSettingsBridge.WriteSettingsState;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -98,7 +98,7 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
                try {
                    getActivity().startActivityAsUser(mSettingsIntent, new UserHandle(mUserId));
                } 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;
@@ -109,8 +109,9 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        if (preference == mSwitchPref) {
            if (mWriteSettingsState != null && (Boolean) newValue != mWriteSettingsState.canWrite()) {
                setCanWriteSettings(!mWriteSettingsState.canWrite());
            if (mWriteSettingsState != null && (Boolean) newValue != mWriteSettingsState
                    .isPermissible()) {
                setCanWriteSettings(!mWriteSettingsState.isPermissible());
                refreshUi();
            }
            return true;
@@ -122,7 +123,6 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
        mAppOpsManager.setMode(AppOpsManager.OP_WRITE_SETTINGS,
                mPackageInfo.applicationInfo.uid, mPackageName, newState
                ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
        canWriteSettings(mPackageName);
    }

    private boolean canWriteSettings(String pkgName) {
@@ -140,17 +140,10 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
        mWriteSettingsState = mAppBridge.getWriteSettingsInfo(mPackageName,
                mPackageInfo.applicationInfo.uid);

        boolean canWrite = mWriteSettingsState.canWrite();
        boolean canWrite = mWriteSettingsState.isPermissible();
        mSwitchPref.setChecked(canWrite);
        mWriteSettingsPrefs.setEnabled(canWrite);

        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;
    }
@@ -166,9 +159,20 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
    }

    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);
    }

    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) {
        // first check if pkg is a system pkg
        boolean isSystem = false;
@@ -180,8 +184,8 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
            }
        } catch (PackageManager.NameNotFoundException e) {
            // pkg doesn't even exist?
            Log.w(TAG, "Package " + pkg + " not found", e);
            return context.getString(R.string.system_alert_window_off);
            Log.w(LOG_TAG, "Package " + pkg + " not found", e);
            return context.getString(R.string.write_settings_off);
        }

        AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context
@@ -189,7 +193,7 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
        List<AppOpsManager.PackageOps> packageOps = appOpsManager.getPackagesForOps(
                APP_OPS_OP_CODE);
        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;
@@ -201,7 +205,7 @@ public class WriteSettingsDetails extends AppInfoWithHeader implements OnPrefere
        }

        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);