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

Commit b9cd3600 authored by David Nelloms's avatar David Nelloms Committed by android-build-merger
Browse files

Merge "Add car-ified UI for special app access pages." into qt-dev

am: 545d4b7a

Change-Id: I2c9ccf9c2dbdf6f614d6959e407f7367437fe6c0
parents c0af8130 545d4b7a
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -24,11 +24,15 @@ import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.android.packageinstaller.DeviceUtils;
import com.android.packageinstaller.role.model.Role;
import com.android.packageinstaller.role.model.Roles;
import com.android.packageinstaller.role.ui.auto.AutoSpecialAppAccessFragment;
import com.android.packageinstaller.role.ui.handheld.HandheldSpecialAppAccessFragment;
import com.android.permissioncontroller.R;

/**
 * Activity for a special app access.
@@ -42,7 +46,6 @@ public class SpecialAppAccessActivity extends FragmentActivity {
     *
     * @param roleName the name of the role for the special app access
     * @param context  the context to create the intent
     *
     * @return an intent to start this activity
     */
    @NonNull
@@ -53,6 +56,11 @@ public class SpecialAppAccessActivity extends FragmentActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (DeviceUtils.isAuto(this)) {
            // Automotive relies on a different theme. Apply before calling super so that
            // fragments are restored properly on configuration changes.
            setTheme(R.style.CarSettings);
        }
        super.onCreate(savedInstanceState);

        getWindow().addSystemFlags(
@@ -78,8 +86,12 @@ public class SpecialAppAccessActivity extends FragmentActivity {
        }

        if (savedInstanceState == null) {
            HandheldSpecialAppAccessFragment fragment =
                    HandheldSpecialAppAccessFragment.newInstance(roleName);
            Fragment fragment;
            if (DeviceUtils.isAuto(this)) {
                fragment = AutoSpecialAppAccessFragment.newInstance(roleName);
            } else {
                fragment = HandheldSpecialAppAccessFragment.newInstance(roleName);
            }
            getSupportFragmentManager().beginTransaction()
                    .add(android.R.id.content, fragment)
                    .commit();
+15 −2
Original line number Diff line number Diff line
@@ -20,9 +20,13 @@ import android.os.Bundle;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.android.packageinstaller.DeviceUtils;
import com.android.packageinstaller.role.ui.auto.AutoSpecialAppAccessListFragment;
import com.android.packageinstaller.role.ui.handheld.HandheldSpecialAppAccessListFragment;
import com.android.permissioncontroller.R;

/**
 * Activity for the list of special app accesses.
@@ -31,14 +35,23 @@ public class SpecialAppAccessListActivity extends FragmentActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (DeviceUtils.isAuto(this)) {
            // Automotive relies on a different theme. Apply before calling super so that
            // fragments are restored properly on configuration changes.
            setTheme(R.style.CarSettings);
        }
        super.onCreate(savedInstanceState);

        getWindow().addSystemFlags(
                WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);

        if (savedInstanceState == null) {
            HandheldSpecialAppAccessListFragment fragment =
                    HandheldSpecialAppAccessListFragment.newInstance();
            Fragment fragment;
            if (DeviceUtils.isAuto(this)) {
                fragment = AutoSpecialAppAccessListFragment.newInstance();
            } else {
                fragment = HandheldSpecialAppAccessListFragment.newInstance();
            }
            getSupportFragmentManager().beginTransaction()
                    .add(android.R.id.content, fragment)
                    .commit();
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import androidx.annotation.Nullable;
import com.android.packageinstaller.role.ui.TwoTargetPreference;

/**
 * Preference to show default app list. Extends {@link TwoTargetPreference} in order to make sure of
 * Preference for use in auto lists. Extends {@link TwoTargetPreference} in order to make sure of
 * shared logic between phone and auto settings UI.
 */
public class AutoSettingsPreference extends TwoTargetPreference {
+101 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.auto;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import androidx.preference.TwoStatePreference;

import com.android.packageinstaller.auto.AutoSettingsFrameFragment;
import com.android.packageinstaller.role.ui.SpecialAppAccessChildFragment;
import com.android.permissioncontroller.R;

/** Automotive fragment for displaying special app access for a role. */
public class AutoSpecialAppAccessFragment extends AutoSettingsFrameFragment implements
        SpecialAppAccessChildFragment.Parent {

    private String mRoleName;

    /**
     * Returns a new instance of {@link AutoSpecialAppAccessFragment} for the given {@code
     * roleName}.
     */
    @NonNull
    public static AutoSpecialAppAccessFragment newInstance(@NonNull String roleName) {
        AutoSpecialAppAccessFragment fragment = new AutoSpecialAppAccessFragment();
        Bundle arguments = new Bundle();
        arguments.putString(Intent.EXTRA_ROLE_NAME, roleName);
        fragment.setArguments(arguments);
        return fragment;
    }

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

        Bundle arguments = getArguments();
        mRoleName = arguments.getString(Intent.EXTRA_ROLE_NAME);
    }

    @Override
    public void onCreatePreferences(Bundle bundle, String s) {
        // Preferences will be added by the child fragment.
    }

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

        if (savedInstanceState == null) {
            SpecialAppAccessChildFragment fragment = SpecialAppAccessChildFragment.newInstance(
                    mRoleName);
            getChildFragmentManager().beginTransaction()
                    .add(fragment, null)
                    .commit();
        }
    }

    @Override
    public void setTitle(@NonNull CharSequence title) {
        setHeaderLabel(title);
    }

    @NonNull
    @Override
    public TwoStatePreference createApplicationPreference(@NonNull Context context) {
        return new SwitchPreference(context);
    }

    @NonNull
    @Override
    public Preference createFooterPreference(@NonNull Context context) {
        Preference preference = new Preference(context);
        preference.setIcon(R.drawable.ic_info_outline);
        preference.setSelectable(false);
        return preference;
    }

    @Override
    public void onPreferenceScreenChanged() {
    }
}
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.auto;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.packageinstaller.auto.AutoSettingsFrameFragment;
import com.android.packageinstaller.role.ui.SpecialAppAccessListChildFragment;
import com.android.packageinstaller.role.ui.TwoTargetPreference;
import com.android.permissioncontroller.R;

/** Automotive fragment for the list of role related special app accesses. */
public class AutoSpecialAppAccessListFragment extends AutoSettingsFrameFragment implements
        SpecialAppAccessListChildFragment.Parent {

    /** Returns a new instance of {@link AutoSpecialAppAccessListFragment}. */
    @NonNull
    public static AutoSpecialAppAccessListFragment newInstance() {
        return new AutoSpecialAppAccessListFragment();
    }

    @Override
    public void onCreatePreferences(Bundle bundle, String s) {
        // Preferences will be added by the child fragment.
    }

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

        if (savedInstanceState == null) {
            SpecialAppAccessListChildFragment fragment =
                    SpecialAppAccessListChildFragment.newInstance();
            getChildFragmentManager().beginTransaction()
                    .add(fragment, /* tag= */ null)
                    .commit();
        }

        setHeaderLabel(getString(R.string.special_app_access));
    }

    @NonNull
    @Override
    public TwoTargetPreference createPreference(@NonNull Context context) {
        return new AutoSettingsPreference(context);
    }

    @Override
    public void onPreferenceScreenChanged() {
    }
}