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

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

Merge "Remove DeviceIndex feature/service."

parents 1980b16c 6632529b
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -3029,9 +3029,6 @@
            android:exported="true"
            android:permission="android.permission.DUMP" />

         <service android:name=".search.DeviceIndexUpdateJobService"
            android:permission="android.permission.BIND_JOB_SERVICE" />

        <!-- Quick Settings tiles for Developer Options -->
        <service
            android:name=".development.qstile.DevelopmentTiles$ShowLayout"
+0 −11
Original line number Diff line number Diff line
@@ -65,14 +65,12 @@ import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.homepage.TopLevelSettings;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.DeviceIndexFeatureProvider;
import com.android.settings.wfd.WifiDisplaySettings;
import com.android.settings.widget.SwitchBar;
import com.android.settingslib.core.instrumentation.Instrumentable;
import com.android.settingslib.core.instrumentation.SharedPreferencesLogger;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.drawer.DashboardCategory;
import com.android.settingslib.utils.ThreadUtils;

import java.util.ArrayList;
import java.util.List;
@@ -514,7 +512,6 @@ public class SettingsActivity extends SettingsBaseActivity
        registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

        updateTilesList();
        updateDeviceIndex();
    }

    @Override
@@ -636,14 +633,6 @@ public class SettingsActivity extends SettingsBaseActivity
        });
    }

    private void updateDeviceIndex() {
        DeviceIndexFeatureProvider indexProvider = FeatureFactory.getFactory(
                this).getDeviceIndexFeatureProvider();

        ThreadUtils.postOnBackgroundThread(
                () -> indexProvider.updateIndex(SettingsActivity.this, false /* force */));
    }

    private void doUpdateTilesList() {
        PackageManager pm = getPackageManager();
        final UserManager um = UserManager.get(this);
+0 −3
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import com.android.settings.enterprise.EnterprisePrivacyFeatureProvider;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.search.DeviceIndexFeatureProvider;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.security.SecurityFeatureProvider;
import com.android.settings.slices.SlicesFeatureProvider;
@@ -106,8 +105,6 @@ public abstract class FeatureFactory {

    public abstract AccountFeatureProvider getAccountFeatureProvider();

    public abstract DeviceIndexFeatureProvider getDeviceIndexFeatureProvider();

    public static final class FactoryNotFoundException extends RuntimeException {
        public FactoryNotFoundException(Throwable throwable) {
            super("Unable to create factory. Did you misconfigure Proguard?", throwable);
+0 −11
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@ import com.android.settings.gestures.AssistGestureFeatureProvider;
import com.android.settings.gestures.AssistGestureFeatureProviderImpl;
import com.android.settings.localepicker.LocaleFeatureProvider;
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
import com.android.settings.search.DeviceIndexFeatureProvider;
import com.android.settings.search.DeviceIndexFeatureProviderImpl;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settings.search.SearchFeatureProviderImpl;
import com.android.settings.security.SecurityFeatureProvider;
@@ -73,7 +71,6 @@ public class FeatureFactoryImpl extends FeatureFactory {
    private UserFeatureProvider mUserFeatureProvider;
    private SlicesFeatureProvider mSlicesFeatureProvider;
    private AccountFeatureProvider mAccountFeatureProvider;
    private DeviceIndexFeatureProviderImpl mDeviceIndexFeatureProvider;

    @Override
    public SupportFeatureProvider getSupportFeatureProvider(Context context) {
@@ -211,12 +208,4 @@ public class FeatureFactoryImpl extends FeatureFactory {
        }
        return mAccountFeatureProvider;
    }

    @Override
    public DeviceIndexFeatureProvider getDeviceIndexFeatureProvider() {
        if (mDeviceIndexFeatureProvider == null) {
            mDeviceIndexFeatureProvider = new DeviceIndexFeatureProviderImpl();
        }
        return mDeviceIndexFeatureProvider;
    }
}
+0 −136
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.search;

import static com.android.settings.slices.SliceDeepLinkSpringBoard.INTENT;
import static com.android.settings.slices.SliceDeepLinkSpringBoard.SETTINGS;

import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.slices.SettingsSliceProvider;

import java.util.List;
import java.util.Locale;

public interface DeviceIndexFeatureProvider {

    String TAG = "DeviceIndex";

    String INDEX_VERSION = "settings:index_version";
    String INDEX_LANGUAGE = "settings:language";

    // Increment when new items are added to ensure they get pushed to the device index.
    String VERSION = Build.FINGERPRINT;

    // When the device language changes, re-index so Slices trigger in device language.
    Locale LANGUAGE = Locale.getDefault();

    default boolean isIndexingEnabled() {
        return false;
    }

    void index(Context context, CharSequence title, Uri sliceUri, Uri launchUri,
            List<String> keywords);

    void clearIndex(Context context);

    default void updateIndex(Context context, boolean force) {
        if (!isIndexingEnabled()) {
            Log.i(TAG, "Skipping: device index is not enabled");
            return;
        }

        if (!Utils.isDeviceProvisioned(context)) {
            Log.w(TAG, "Skipping: device is not provisioned");
            return;
        }

        final ComponentName jobComponent = new ComponentName(context.getPackageName(),
                DeviceIndexUpdateJobService.class.getName());

        try {
            final int callerUid = Binder.getCallingUid();
            final ServiceInfo si = context.getPackageManager().getServiceInfo(jobComponent,
                    PackageManager.MATCH_DIRECT_BOOT_AWARE
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
            if (si == null) {
                Log.w(TAG, "Skipping: No such service " + jobComponent);
                return;
            }
            if (si.applicationInfo.uid != callerUid) {
                Log.w(TAG, "Skipping: Uid cannot schedule DeviceIndexUpdate: " + callerUid);
                return;
            }
        } catch (PackageManager.NameNotFoundException e) {
            Log.w(TAG, "Skipping: error finding DeviceIndexUpdateJobService from packageManager");
            return;
        }

        if (!force && skipIndex(context)) {
            Log.i(TAG, "Skipping: already indexed.");
            // No need to update.
            return;
        }

        // Prevent scheduling multiple jobs
        setIndexState(context);

        final int jobId = context.getResources().getInteger(R.integer.device_index_update);
        // Schedule a job so that we know it'll be able to complete, but try to run as
        // soon as possible.
        context.getSystemService(JobScheduler.class).schedule(
                new JobInfo.Builder(jobId, jobComponent)
                        .setPersisted(false)
                        .setMinimumLatency(1000)
                        .setOverrideDeadline(1)
                        .build());

    }

    static Uri createDeepLink(String s) {
        return new Uri.Builder().scheme(SETTINGS)
                .authority(SettingsSliceProvider.SLICE_AUTHORITY)
                .appendQueryParameter(INTENT, s)
                .build();
    }

    static boolean skipIndex(Context context) {
        final boolean isSameVersion = TextUtils.equals(
                Settings.Secure.getString(context.getContentResolver(), INDEX_VERSION), VERSION);
        final boolean isSameLanguage = TextUtils.equals(
                Settings.Secure.getString(context.getContentResolver(), INDEX_LANGUAGE),
                LANGUAGE.toString());
        return isSameLanguage && isSameVersion;
    }

    static void setIndexState(Context context) {
        Settings.Secure.putString(context.getContentResolver(), INDEX_VERSION, VERSION);
        Settings.Secure.putString(context.getContentResolver(), INDEX_LANGUAGE,
                LANGUAGE.toString());
    }
}
Loading