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

Commit 21b9d15c authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

Merge "Hide TARE page when disabled." into udc-dev

parents f77643be d6409c4e
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -669,9 +669,6 @@
        <Preference
            android:key="tare"
            android:title="@string/tare_title" >
            <intent
                android:targetPackage="com.android.settings"
                android:targetClass="com.android.settings.development.tare.TareHomePage" />
        </Preference>

        <SwitchPreference
+1 −0
Original line number Diff line number Diff line
@@ -710,6 +710,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
        controllers.add(new DefaultLaunchPreferenceController(context, "density"));
        controllers.add(new DefaultLaunchPreferenceController(context, "background_check"));
        controllers.add(new DefaultLaunchPreferenceController(context, "inactive_apps"));
        controllers.add(new TarePreferenceController(context));
        controllers.add(new AutofillCategoryController(context, lifecycle));
        controllers.add(new AutofillLoggingLevelPreferenceController(context, lifecycle));
        controllers.add(new AutofillResetOptionsPreferenceController(context));
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.development;

import android.app.tare.EconomyManager;
import android.content.Context;
import android.content.Intent;
import android.os.UserManager;
import android.provider.Settings;

import androidx.preference.Preference;

import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.development.tare.TareHomePage;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;

/** PreferenceController that serves as an entry point to the TARE configuration screen. */
public class TarePreferenceController extends
        DeveloperOptionsPreferenceController implements PreferenceControllerMixin {

    private static final String KEY_TARE = "tare";

    private final EconomyManager mEconomyManager;
    private final UserManager mUserManager;

    public TarePreferenceController(Context context) {
        super(context);
        mEconomyManager = context.getSystemService(EconomyManager.class);
        mUserManager = context.getSystemService(UserManager.class);
    }

    @Override
    public boolean isAvailable() {
        // Enable the UI if the dedicated flag enables it or if TARE itself is on.
        final boolean settingEnabled = Settings.Global.getInt(
                mContext.getContentResolver(), Settings.Global.SHOW_TARE_DEVELOPER_OPTIONS, 0) == 1;
        final boolean isTareUiEnabled = settingEnabled
                || mEconomyManager.getEnabledMode() != EconomyManager.ENABLED_MODE_OFF;
        return isTareUiEnabled
                && !mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES);
    }

    @Override
    public String getPreferenceKey() {
        return KEY_TARE;
    }

    @Override
    public boolean handlePreferenceTreeClick(Preference preference) {
        if (!KEY_TARE.equals(preference.getKey())) {
            return false;
        }
        mContext.startActivity(new Intent(mContext, TareHomePage.class));
        return false;
    }
}