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

Commit aecc5ef0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make roles searchable in settings."

parents 217f1aca b8766c0c
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -201,6 +201,17 @@
        <activity android:name="com.android.packageinstaller.role.ui.SpecialAppAccessActivity"
                  android:theme="@style/Settings" />

        <activity android:name="com.android.packageinstaller.role.ui.RoleSearchTrampolineActivity"
                  android:excludeFromRecents="true"
                  android:noHistory="true"
                  android:theme="@android:style/Theme.NoDisplay">
            <intent-filter android:priority="1">
                <action android:name="com.android.permissioncontroller.settingssearch.action.MANAGE_DEFAULT_APP" />
                <action android:name="com.android.permissioncontroller.settingssearch.action.MANAGE_SPECIAL_APP_ACCESS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <provider android:name="com.android.packageinstaller.permission.service.PermissionSearchIndexablesProvider"
            android:authorities="com.android.permissioncontroller"
            android:multiprocess="false"
@@ -212,6 +223,16 @@
            </intent-filter>
        </provider>

        <provider android:name="com.android.packageinstaller.role.service.RoleSearchIndexablesProvider"
                  android:authorities="com.android.permissioncontroller.role"
                  android:exported="true"
                  android:grantUriPermissions="true"
                  android:permission="android.permission.READ_SEARCH_INDEXABLES">
            <intent-filter>
                <action android:name="android.content.action.SEARCH_INDEXABLES_PROVIDER" />
            </intent-filter>
        </provider>

        <service android:name="com.android.packageinstaller.permission.service.PermissionControllerServiceImpl">
            <intent-filter android:priority="1">
                <action android:name="android.permission.PermissionControllerService"/>
+6 −0
Original line number Diff line number Diff line
@@ -486,6 +486,9 @@
    <!-- Text for the dialog listing the enabled accessibility services when there are more than one [CHAR LIMIT=none] -->
    <string name="accessibility_service_dialog_bottom_text_multiple">These apps can view your screen, actions, and inputs, perform actions, and control the display.</string>

    <!-- Keyword in the Settings app's search functionality that can be used to find links to the default app management screens [CHAR LIMIT=none] -->
    <string name="default_app_search_keyword">default apps</string>

    <!-- Title for page of managing default apps. [CHAR LIMIT=30] -->
    <string name="default_apps">Default apps</string>

@@ -505,6 +508,9 @@
    <!-- Label when there are no apps available for a default app [CHAR LIMIT=30] -->
    <string name="default_app_no_apps">No apps</string>

    <!-- Keyword in the Settings app's search functionality that can be used to find links to the special app access management screens [CHAR LIMIT=none] -->
    <string name="special_app_access_search_keyword">special app access</string>

    <!-- Title for page of managing special app access. [CHAR LIMIT=30] -->
    <string name="special_app_access">Special app access</string>

+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.packageinstaller.role.service;

import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.provider.SearchIndexablesContract;
import android.util.ArrayMap;

import androidx.annotation.Nullable;

import com.android.packageinstaller.permission.service.BaseSearchIndexablesProvider;
import com.android.packageinstaller.role.model.Role;
import com.android.packageinstaller.role.model.Roles;
import com.android.permissioncontroller.R;

/**
 * {@link android.provider.SearchIndexablesProvider} for roles.
 */
public class RoleSearchIndexablesProvider extends BaseSearchIndexablesProvider {

    public static final String ACTION_MANAGE_DEFAULT_APP =
            "com.android.permissioncontroller.settingssearch.action.MANAGE_DEFAULT_APP";

    public static final String ACTION_MANAGE_SPECIAL_APP_ACCESS =
            "com.android.permissioncontroller.settingssearch.action.MANAGE_SPECIAL_APP_ACCESS";

    @Nullable
    @Override
    public Cursor queryRawData(@Nullable String[] projection) {
        MatrixCursor cursor = new MatrixCursor(SearchIndexablesContract.INDEXABLES_RAW_COLUMNS);
        Context context = getContext();
        ArrayMap<String, Role> roles = Roles.get(context);
        int rolesSize = roles.size();
        for (int i = 0; i < rolesSize; i++) {
            Role role = roles.valueAt(i);

            String label = context.getString(role.getLabelResource());
            boolean isExclusive = role.isExclusive();
            cursor.newRow()
                    .add(SearchIndexablesContract.RawData.COLUMN_RANK, 0)
                    .add(SearchIndexablesContract.RawData.COLUMN_TITLE, label)
                    .add(SearchIndexablesContract.RawData.COLUMN_KEYWORDS, label + ", "
                            + getContext().getString(isExclusive
                            ? R.string.default_app_search_keyword
                            : R.string.special_app_access_search_keyword))
                    .add(SearchIndexablesContract.RawData.COLUMN_KEY, createRawDataKey(
                            role.getName(), context))
                    .add(SearchIndexablesContract.RawData.COLUMN_INTENT_ACTION, isExclusive
                            ? ACTION_MANAGE_DEFAULT_APP : ACTION_MANAGE_SPECIAL_APP_ACCESS);
        }
        return cursor;
    }
}
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.packageinstaller.role.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;

import com.android.packageinstaller.role.service.RoleSearchIndexablesProvider;

/**
 * Trampoline activity for activities exposed from
 * {@link com.android.packageinstaller.role.service.RoleSearchIndexablesProvider}.
 */
public class RoleSearchTrampolineActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        if (!RoleSearchIndexablesProvider.isIntentValid(intent, this)) {
            finish();
            return;
        }

        String action = intent.getAction();
        if (action == null) {
            finish();
            return;
        }

        Intent newIntent;
        switch (action) {
            case RoleSearchIndexablesProvider.ACTION_MANAGE_DEFAULT_APP:
                newIntent = DefaultAppActivity.createIntent(
                        // We don't support work profile in search.
                        RoleSearchIndexablesProvider.getOriginalKey(intent), Process.myUserHandle(),
                        this);
                break;
            case RoleSearchIndexablesProvider.ACTION_MANAGE_SPECIAL_APP_ACCESS:
                newIntent = SpecialAppAccessActivity.createIntent(
                        RoleSearchIndexablesProvider.getOriginalKey(intent), this);
                break;
            default:
                finish();
                return;
        }

        newIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
        startActivity(newIntent);
        finish();
    }
}