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

Commit db775bda authored by Tim Murray's avatar Tim Murray Committed by Android (Google) Code Review
Browse files

Merge "JobScheduler: remove TARE" into main

parents ca8f6abe 431e8600
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -740,7 +740,6 @@ 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));
+0 −70
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;
    }
}
+0 −173
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.tare;

import android.app.Fragment;
import android.app.tare.EconomyManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

import androidx.annotation.Nullable;

import com.android.settings.R;

/**
 * Creates the AlarmManager fragment to display all the AlarmManager factors
 * when the AlarmManager policy is chosen in the dropdown TARE menu.
 */
public class AlarmManagerFragment extends Fragment implements
        TareFactorController.DataChangeListener {

    private TareFactorController mFactorController;

    private TareFactorExpandableListAdapter mExpandableListAdapter;

    private String[] mGroups;
    private String[][] mChildren;
    private String[][] mKeys;

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

        mFactorController = TareFactorController.getInstance(getContext());
        populateArrays();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.tare_policy_fragment, null);
        ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.factor_list);
        mExpandableListAdapter = new TareFactorExpandableListAdapter(
                mFactorController, LayoutInflater.from(getActivity()), mGroups, mChildren, mKeys);
        elv.setGroupIndicator(null);
        elv.setAdapter(mExpandableListAdapter);
        elv.setOnChildClickListener(new OnChildClickListener() {
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                final String key = mExpandableListAdapter.getKey(groupPosition, childPosition);
                mFactorController.createDialog(key).show(getFragmentManager(), key);
                return true;
            }
        });
        return v;
    }

    @Override
    public void onStart() {
        super.onStart();
        mFactorController.registerListener(this);
    }

    @Override
    public void onStop() {
        mFactorController.unregisterListener(this);
        super.onStop();
    }

    @Override
    public void onDataChanged() {
        mExpandableListAdapter.notifyDataSetChanged();
    }

    private void populateArrays() {
        final Resources resources = getResources();

        mGroups = new String[]{
                resources.getString(R.string.tare_consumption_limits),
                resources.getString(R.string.tare_balances),
                // resources.getString(R.string.tare_modifiers),
                resources.getString(R.string.tare_actions_ctp),
                resources.getString(R.string.tare_actions_base_price),
                resources.getString(R.string.tare_rewards_instantaneous),
                resources.getString(R.string.tare_rewards_ongoing),
                resources.getString(R.string.tare_rewards_max)
        };

        mChildren = new String[][]{
                resources.getStringArray(R.array.tare_consumption_limit_subfactors),
                resources.getStringArray(R.array.tare_app_balance_subfactors),
                // TODO: support
                // resources.getStringArray(R.array.tare_modifiers_subfactors),
                resources.getStringArray(R.array.tare_alarm_manager_actions),
                resources.getStringArray(R.array.tare_alarm_manager_actions),
                resources.getStringArray(R.array.tare_rewards_subfactors),
                {resources.getString(R.string.tare_top_activity)},
                resources.getStringArray(R.array.tare_rewards_subfactors)
        };

        mKeys = new String[][]{
                {
                        EconomyManager.KEY_AM_INITIAL_CONSUMPTION_LIMIT,
                        EconomyManager.KEY_AM_MIN_CONSUMPTION_LIMIT,
                        EconomyManager.KEY_AM_MAX_CONSUMPTION_LIMIT,
                },
                {
                        EconomyManager.KEY_AM_MAX_SATIATED_BALANCE,
                        EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_EXEMPTED,
                        EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP,
                        EconomyManager.KEY_AM_MIN_SATIATED_BALANCE_OTHER_APP
                },
                // {},
                {
                        EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_EXACT_WAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_CTP,
                        EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_CTP
                },
                {
                        EconomyManager.KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_WAKEUP_BASE_PRICE,
                        EconomyManager
                                .KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_WAKEUP_BASE_PRICE,
                        EconomyManager.KEY_AM_ACTION_ALARM_EXACT_WAKEUP_BASE_PRICE,
                        EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_WAKEUP_BASE_PRICE,
                        EconomyManager
                                .KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_EXACT_NONWAKEUP_BASE_PRICE,
                        EconomyManager
                                .KEY_AM_ACTION_ALARM_ALLOW_WHILE_IDLE_INEXACT_NONWAKEUP_BASE_PRICE,
                        EconomyManager.KEY_AM_ACTION_ALARM_EXACT_NONWAKEUP_BASE_PRICE,
                        EconomyManager.KEY_AM_ACTION_ALARM_INEXACT_NONWAKEUP_BASE_PRICE,
                        EconomyManager.KEY_AM_ACTION_ALARM_ALARMCLOCK_BASE_PRICE
                },
                {
                        EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_INSTANT,
                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_INSTANT,
                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_INSTANT,
                        EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_INSTANT,
                        EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_INSTANT,
                },
                {EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_ONGOING},
                {
                        EconomyManager.KEY_AM_REWARD_TOP_ACTIVITY_MAX,
                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_SEEN_MAX,
                        EconomyManager.KEY_AM_REWARD_NOTIFICATION_INTERACTION_MAX,
                        EconomyManager.KEY_AM_REWARD_WIDGET_INTERACTION_MAX,
                        EconomyManager.KEY_AM_REWARD_OTHER_USER_INTERACTION_MAX,
                }
        };
    }
}
+0 −101
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.tare;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.android.settings.R;
import com.android.settingslib.widget.SettingsSpinnerAdapter;

/**
 * Dropdown activity to allow for the user to easily switch between the different TARE
 * policies in the developer options of settings. Depending on what is chosen, the fragment
 * containing that specific policies' factors will be generated.
 */
public class DropdownActivity extends Activity {

    private Fragment mAlarmManagerFragment;
    private Fragment mJobSchedulerFragment;
    private Spinner mSpinner;
    static final String EXTRA_POLICY = "policy";
    static final int POLICY_ALARM_MANAGER = 0;
    static final int POLICY_JOB_SCHEDULER = 1;
    private static final int DEFAULT_POLICY = POLICY_ALARM_MANAGER;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tare_dropdown_page);

        // Determines what policy fragment to open up to
        Intent intent = getIntent();
        int policy = intent.getIntExtra(EXTRA_POLICY, DEFAULT_POLICY);

        mSpinner = findViewById(R.id.spinner);
        mAlarmManagerFragment = new AlarmManagerFragment();
        mJobSchedulerFragment = new JobSchedulerFragment();

        String[] policies = getResources().getStringArray(R.array.tare_policies);

        ArrayAdapter<String> arrayAdapter = new SettingsSpinnerAdapter<String>(this);
        arrayAdapter.addAll(policies);
        mSpinner.setAdapter(arrayAdapter);

        mSpinner.setSelection(policy);
        selectFragment(policy);

        mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position,
                    long id) {
                selectFragment(position);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }
        });
    }

    /** Selects the correct policy fragment to display based on user selection */
    private void selectFragment(int policy) {
        switch (policy) {
            case POLICY_ALARM_MANAGER:
                openFragment(mAlarmManagerFragment);
                break;
            case POLICY_JOB_SCHEDULER:
                openFragment(mJobSchedulerFragment);
                break;
            default:
                openFragment(mAlarmManagerFragment);
        }
    }

    /** Opens the correct policy fragment */
    private void openFragment(Fragment fragment) {
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.replace(R.id.frame_layout, fragment);
        fragmentTransaction.commit();
    }
}
+0 −178
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.tare;

import android.app.Fragment;
import android.app.tare.EconomyManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

import androidx.annotation.Nullable;

import com.android.settings.R;

/**
 * Creates the JobScheduler fragment to display all the JobScheduler factors
 * when the JobScheduler policy is chosen in the dropdown TARE menu.
 */
public class JobSchedulerFragment extends Fragment implements
        TareFactorController.DataChangeListener {

    private TareFactorController mFactorController;

    private TareFactorExpandableListAdapter mExpandableListAdapter;

    private String[] mGroups;
    private String[][] mChildren;
    private String[][] mKeys;

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

        mFactorController = TareFactorController.getInstance(getContext());
        populateArrays();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.tare_policy_fragment, null);
        ExpandableListView elv = (ExpandableListView) v.findViewById(R.id.factor_list);
        mExpandableListAdapter = new TareFactorExpandableListAdapter(
                mFactorController, LayoutInflater.from(getActivity()), mGroups, mChildren, mKeys);
        elv.setGroupIndicator(null);
        elv.setAdapter(mExpandableListAdapter);
        elv.setOnChildClickListener(new OnChildClickListener() {
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
                final String key = mExpandableListAdapter.getKey(groupPosition, childPosition);
                mFactorController.createDialog(key).show(getFragmentManager(), key);
                return true;
            }
        });

        return v;
    }

    @Override
    public void onStart() {
        super.onStart();
        mFactorController.registerListener(this);
    }

    @Override
    public void onStop() {
        mFactorController.unregisterListener(this);
        super.onStop();
    }

    @Override
    public void onDataChanged() {
        mExpandableListAdapter.notifyDataSetChanged();
    }

    private void populateArrays() {
        final Resources resources = getResources();

        mGroups = new String[]{
                resources.getString(R.string.tare_consumption_limits),
                resources.getString(R.string.tare_balances),
                // mResources.getString(R.string.tare_modifiers),
                resources.getString(R.string.tare_actions_ctp),
                resources.getString(R.string.tare_actions_base_price),
                resources.getString(R.string.tare_rewards_instantaneous),
                resources.getString(R.string.tare_rewards_ongoing),
                resources.getString(R.string.tare_rewards_max)
        };

        mChildren = new String[][]{
                resources.getStringArray(R.array.tare_consumption_limit_subfactors),
                resources.getStringArray(R.array.tare_job_scheduler_app_balance_subfactors),
                // TODO: support
                // mResources.getStringArray(R.array.tare_modifiers_subfactors),
                resources.getStringArray(R.array.tare_job_scheduler_actions),
                resources.getStringArray(R.array.tare_job_scheduler_actions),
                resources.getStringArray(R.array.tare_job_scheduler_rewards_subfactors),
                {resources.getString(R.string.tare_top_activity)},
                resources.getStringArray(R.array.tare_job_scheduler_rewards_subfactors)
        };

        mKeys = new String[][]{
                {
                        EconomyManager.KEY_JS_INITIAL_CONSUMPTION_LIMIT,
                        EconomyManager.KEY_JS_MIN_CONSUMPTION_LIMIT,
                        EconomyManager.KEY_JS_MAX_CONSUMPTION_LIMIT,
                },
                {
                        EconomyManager.KEY_JS_MAX_SATIATED_BALANCE,
                        EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_EXEMPTED,
                        EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_HEADLESS_SYSTEM_APP,
                        EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_OTHER_APP,
                        EconomyManager.KEY_JS_MIN_SATIATED_BALANCE_INCREMENT_APP_UPDATER,
                },
                // {},
                {
                        EconomyManager.KEY_JS_ACTION_JOB_MAX_START_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_MAX_RUNNING_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_HIGH_START_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_HIGH_RUNNING_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_START_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_RUNNING_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_LOW_START_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_LOW_RUNNING_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_MIN_START_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_MIN_RUNNING_CTP,
                        EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_CTP
                },
                {
                        EconomyManager.KEY_JS_ACTION_JOB_MAX_START_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_MAX_RUNNING_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_HIGH_START_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_HIGH_RUNNING_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_START_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_DEFAULT_RUNNING_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_LOW_START_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_LOW_RUNNING_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_MIN_START_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_MIN_RUNNING_BASE_PRICE,
                        EconomyManager.KEY_JS_ACTION_JOB_TIMEOUT_PENALTY_BASE_PRICE
                },
                {
                        EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_INSTANT,
                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_INSTANT,
                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_INSTANT,
                        EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_INSTANT,
                        EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_INSTANT,
                        EconomyManager.KEY_JS_REWARD_APP_INSTALL_INSTANT,
                },
                {EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_ONGOING},
                {
                        EconomyManager.KEY_JS_REWARD_TOP_ACTIVITY_MAX,
                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_SEEN_MAX,
                        EconomyManager.KEY_JS_REWARD_NOTIFICATION_INTERACTION_MAX,
                        EconomyManager.KEY_JS_REWARD_WIDGET_INTERACTION_MAX,
                        EconomyManager.KEY_JS_REWARD_OTHER_USER_INTERACTION_MAX,
                        EconomyManager.KEY_JS_REWARD_APP_INSTALL_MAX,
                }
        };
    }
}
Loading