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

Commit d3fe360d authored by Ricky Wai's avatar Ricky Wai Committed by Android (Google) Code Review
Browse files

Merge "Add restricted settings UI in Settings accessibility screeen"

parents 8f94676b c76a11f0
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -3620,6 +3620,18 @@
            </intent-filter>
        </activity>

        <activity android:name=".ActionDisabledByAppOpsDialog"
                  android:theme="@style/Theme.AlertDialog"
                  android:taskAffinity="com.android.settings.appops"
                  android:excludeFromRecents="true"
                  android:exported="false"
                  android:launchMode="singleTop">
            <intent-filter android:priority="1">
                <action android:name="android.settings.SHOW_RESTRICTED_SETTING_DIALOG" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity
            android:name="Settings$ManageExternalStorageActivity"
            android:exported="true"
+9 −0
Original line number Diff line number Diff line
@@ -4641,6 +4641,8 @@
    <string name="clear_user_data_text">Clear storage</string>
    <!-- Manage applications, restore updated system application to factory version -->
    <string name="app_factory_reset">Uninstall updates</string>
    <!-- [CHAR LIMIT=50] Manage applications, unlock restricted settings from lock screen title -->
    <string name="app_restricted_settings_lockscreen_title">Unlock restricted settings</string>
    <!-- Manage applications, individual application info screen, screen, message text under Launch by default heading. This is present if the app is set as a default for some actions. -->
    <string name="auto_launch_enable_text">Some activities you\u2019ve selected open in this app by default.</string>
    <!-- Manage applications, individual application info screen, screen, message text under Launch by default heading. This is present if the app was given user permission to create widgets. -->
@@ -12013,6 +12015,10 @@
    <string name="do_disclosure_learn_more_separator">" "</string>
    <!-- Button label to allow the user to view additional information [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=2416766240581561009] -->
    <string name="learn_more">Learn more</string>
    <!--Title for dialog displayed to tell user that settings are blocked by setting restrictions [CHAR LIMIT=50] -->
    <string name="blocked_by_restricted_settings_title">Restricted Settings</string>
    <!--Content for dialog displayed to tell user that settings are blocked by setting restrictions [CHAR LIMIT=100] -->
    <string name="blocked_by_restricted_settings_content">For your security, this setting is currently unavailable.</string>
    <!-- Financed device Privacy --> <skip />
@@ -12257,6 +12263,9 @@
    <!-- Help URI, prevent ringing gesture [DO NOT TRANSLATE] -->
    <string name="help_uri_prevent_ringing_gesture" translatable="false"></string>
    <!-- Help URI, action disabled by restricted settings [DO NOT TRANSLATE] -->
    <string name="help_url_action_disabled_by_restricted_settings" translatable="false"></string>
    <!-- Title label for Priority mode suggestion, which is displayed in Settings homepage [CHAR LIMIT=100] -->
    <string name="zen_suggestion_title" translatable="false">Update Priority mode</string>
+65 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings;

import android.app.Activity;
import android.app.AppOpsManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class ActionDisabledByAppOpsDialog extends Activity
        implements DialogInterface.OnDismissListener {

    private static final String TAG = "ActionDisabledByAppOpsDialog";

    private ActionDisabledByAppOpsHelper mDialogHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDialogHelper = new ActionDisabledByAppOpsHelper(this);
        mDialogHelper.prepareDialogBuilder()
                .setOnDismissListener(this)
                .show();
        updateAppOps();
    }

    private void updateAppOps() {
        final Intent intent = getIntent();
        final String packageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
        final int uid = intent.getIntExtra(Intent.EXTRA_UID, android.os.Process.INVALID_UID);
        getSystemService(AppOpsManager.class)
                .setMode(AppOpsManager.OP_ACCESS_RESTRICTED_SETTINGS,
                        uid,
                        packageName,
                        AppOpsManager.MODE_IGNORED);
    }

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        mDialogHelper.updateDialog();
        updateAppOps();
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        finish();
    }
}
+88 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;

import com.android.settingslib.HelpUtils;

final class ActionDisabledByAppOpsHelper {

    private final ViewGroup mDialogView;
    private final Activity mActivity;

    ActionDisabledByAppOpsHelper(Activity activity) {
        mActivity = activity;
        mDialogView = (ViewGroup) LayoutInflater.from(mActivity).inflate(
                R.layout.support_details_dialog, null);
    }

    public AlertDialog.Builder prepareDialogBuilder() {
        final String helpUrl = mActivity.getString(
                R.string.help_url_action_disabled_by_restricted_settings);
        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
                .setPositiveButton(R.string.okay, null)
                .setView(mDialogView);
        if (!TextUtils.isEmpty(helpUrl)) {
            builder.setNeutralButton(R.string.learn_more,
                    (DialogInterface.OnClickListener) (dialog, which) -> {
                        final Intent intent = HelpUtils.getHelpIntent(mActivity,
                                helpUrl, mActivity.getClass().getName());
                        if (intent != null) {
                            mActivity.startActivity(intent);
                        }
                    });
        }
        initializeDialogViews(mDialogView);
        return builder;
    }

    public void updateDialog() {
        initializeDialogViews(mDialogView);
    }

    private void initializeDialogViews(View root) {
        setSupportTitle(root);
        setSupportDetails(root);
    }

    @VisibleForTesting
    void setSupportTitle(View root) {
        final TextView titleView = root.findViewById(R.id.admin_support_dialog_title);
        if (titleView == null) {
            return;
        }
        titleView.setText(R.string.blocked_by_restricted_settings_title);
    }

    void setSupportDetails(final View root) {
        final TextView textView = root.findViewById(R.id.admin_support_msg);
        textView.setText(R.string.blocked_by_restricted_settings_content);
    }
}
Loading