Snap for 6300905 from e861749b6537943ed0197dc712f8a8722baf0cac to qt-d4-release Change-Id: I05b61041f5758a285624a9399276cff0a17ec14d
diff --git a/Android.bp b/Android.bp index 963ca2b..3bc0ddb 100644 --- a/Android.bp +++ b/Android.bp
@@ -42,6 +42,8 @@ "src/**/*.proto", ], + libs: ["android.car-stubs"], + static_libs: [ "iconloader", "com.google.android.material_material", @@ -69,7 +71,8 @@ "SettingsLibActionBarShadow", "SettingsLibProgressBar", "androidx.annotation_annotation", - "permissioncontroller-statsd" + "permissioncontroller-statsd", + "car-ui-lib-bp" ], proto: {
diff --git a/proguard.flags b/proguard.flags index a2e5884..91f7d38 100644 --- a/proguard.flags +++ b/proguard.flags
@@ -11,3 +11,5 @@ -keep class * implements com.android.packageinstaller.role.model.RoleBehavior { *; } + +-keep class com.android.car.ui.** {*;}
diff --git a/res/layout/car_settings_frame.xml b/res/layout/car_settings_frame.xml deleted file mode 100644 index 4381d01..0000000 --- a/res/layout/car_settings_frame.xml +++ /dev/null
@@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - 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. ---> - -<LinearLayout - xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> - - <androidx.constraintlayout.widget.ConstraintLayout - android:layout_width="match_parent" - android:layout_height="@*android:dimen/car_app_bar_height"> - - <FrameLayout - android:id="@+id/back_button" - android:layout_width="0dp" - android:layout_height="0dp" - android:background="?android:attr/selectableItemBackground" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toStartOf="@+id/start_margin" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"> - <ImageView - android:layout_width="@*android:dimen/car_primary_icon_size" - android:layout_height="@*android:dimen/car_primary_icon_size" - android:layout_gravity="center" - android:scaleType="fitCenter" - android:src="@drawable/ic_arrow_back" - android:tint="?android:attr/textColorPrimary"/> - </FrameLayout> - - <androidx.constraintlayout.widget.Guideline - android:id="@+id/start_margin" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical" - app:layout_constraintGuide_begin="@*android:dimen/action_bar_margin_start"/> - - <TextView - android:id="@+id/label" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:singleLine="true" - android:textAppearance="?android:attr/textAppearanceLarge" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintStart_toEndOf="@+id/start_margin" - app:layout_constraintTop_toTopOf="parent"/> - - <Button - android:id="@+id/action" - style="@*android:style/ActionBarButton" - android:layout_width="wrap_content" - android:layout_height="0dp" - android:layout_marginEnd="@*android:dimen/action_bar_button_margin" - android:visibility="gone" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toTopOf="parent"/> - </androidx.constraintlayout.widget.ConstraintLayout> - - <ProgressBar - android:id="@+id/progress_bar" - style="@android:style/Widget.DeviceDefault.ProgressBar.Horizontal" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:indeterminate="true" - android:visibility="gone"/> - - <FrameLayout - android:id="@android:id/list_container" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:paddingEnd="@*android:dimen/car_margin" - android:paddingStart="@*android:dimen/car_margin"/> -</LinearLayout>
diff --git a/res/values/overlayable.xml b/res/values/overlayable.xml index 6d0dda5..2bcb571 100644 --- a/res/values/overlayable.xml +++ b/res/values/overlayable.xml
@@ -248,14 +248,8 @@ <item type="dimen" name="car_icon_size" /> <!-- END CAR DIMENS --> - <!-- START CAR STYLES --> - <item type="style" name="CarPreferenceFragment" /> - <item type="style" name="CarPreferenceFragmentList" /> - <!-- END CAR STYLES --> - <!-- START CAR THEMES --> <item type="style" name="CarSettings" /> - <item type="style" name="CarPreferenceTheme" /> <!-- END CAR THEMES --> </policy>
diff --git a/res/values/styles.xml b/res/values/styles.xml index 5516dbe..55c4778 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml
@@ -869,21 +869,4 @@ <!-- END ACCESSIBILITY SERVICE DIALOG ITEM --> - <!-- START CAR SETTINGS PREFERENCE STYLES --> - - <style name="CarPreferenceFragment"> - <item name="android:layout">@layout/car_settings_frame</item> - </style> - - <style name="CarPreferenceFragmentList"> - <item name="android:paddingTop">0dp</item> - <item name="android:paddingBottom">0dp</item> - <item name="android:paddingStart">0dp</item> - <item name="android:paddingEnd">0dp</item> - <item name="android:paddingLeft">0dp</item> - <item name="android:paddingRight">0dp</item> - </style> - - <!-- END CAR SETTINGS PREFERENCE STYLES --> - </resources>
diff --git a/res/values/themes.xml b/res/values/themes.xml index b8ed550..fb45640 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml
@@ -77,14 +77,8 @@ parent="@android:style/Theme.DeviceDefault.Light.Dialog.NoActionBar"> </style> - <style name="CarSettings" parent="@android:style/Theme.DeviceDefault.NoActionBar"> - <item name="preferenceTheme">@style/CarPreferenceTheme</item> + <style name="CarSettings" parent="Theme.CarUi"> <item name="carDividerColor">@*android:color/car_list_divider</item> </style> - <style name="CarPreferenceTheme"> - <item name="preferenceFragmentCompatStyle">@style/CarPreferenceFragment</item> - <item name="preferenceFragmentListStyle">@style/CarPreferenceFragmentList</item> - </style> - </resources>
diff --git a/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java b/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java index ea8987e..d89ced7 100644 --- a/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java +++ b/src/com/android/packageinstaller/auto/AutoSettingsFrameFragment.java
@@ -21,22 +21,21 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ProgressBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.preference.PreferenceFragmentCompat; +import com.android.car.ui.preference.PreferenceFragment; +import com.android.car.ui.toolbar.MenuItem; +import com.android.car.ui.toolbar.ToolbarController; import com.android.permissioncontroller.R; -/** Common settings frame for car related settings in permission controller. */ -public abstract class AutoSettingsFrameFragment extends PreferenceFragmentCompat { +import java.util.Collections; - private TextView mLabelView; - private ProgressBar mProgressBar; - private Button mAction; +/** Common settings frame for car related settings in permission controller. */ +public abstract class AutoSettingsFrameFragment extends PreferenceFragment { + + private ToolbarController mToolbar; private CharSequence mLabel; private boolean mIsLoading; @@ -48,16 +47,10 @@ @Nullable Bundle savedInstanceState) { View rootView = super.onCreateView(inflater, container, savedInstanceState); - View backButton = rootView.findViewById(R.id.back_button); - backButton.setOnClickListener(v -> getActivity().onBackPressed()); + mToolbar = rootView.findViewById(R.id.toolbar); - mLabelView = rootView.findViewById(R.id.label); updateHeaderLabel(); - - mProgressBar = rootView.findViewById(R.id.progress_bar); updateLoading(); - - mAction = rootView.findViewById(R.id.action); updateAction(); return rootView; @@ -66,6 +59,10 @@ /** Sets the header text of this fragment. */ public void setHeaderLabel(CharSequence label) { mLabel = label; + if (getPreferenceScreen() != null) { + // Needed because CarUi's preference fragment reads this title + getPreferenceScreen().setTitle(mLabel); + } updateHeaderLabel(); } @@ -75,8 +72,8 @@ } private void updateHeaderLabel() { - if (mLabelView != null) { - mLabelView.setText(mLabel); + if (mToolbar != null) { + mToolbar.setTitle(mLabel); } } @@ -91,8 +88,12 @@ } private void updateLoading() { - if (mProgressBar != null) { - mProgressBar.setVisibility(mIsLoading ? View.VISIBLE : View.GONE); + if (mToolbar != null) { + if (mIsLoading) { + mToolbar.showProgressBar(); + } else { + mToolbar.hideProgressBar(); + } } } @@ -107,15 +108,16 @@ } private void updateAction() { - if (mAction == null) { + if (mToolbar == null) { return; } if (!TextUtils.isEmpty(mActionLabel) && mActionOnClickListener != null) { - mAction.setText(mActionLabel); - mAction.setOnClickListener(mActionOnClickListener); - mAction.setVisibility(View.VISIBLE); + mToolbar.setMenuItems(Collections.singletonList(MenuItem.builder(getContext()) + .setTitle(mActionLabel) + .setOnClickListener(i -> mActionOnClickListener.onClick(null)) + .build())); } else { - mAction.setVisibility(View.GONE); + mToolbar.setMenuItems(null); } } }
diff --git a/src/com/android/packageinstaller/permission/ui/auto/AutoAllAppPermissionsFragment.java b/src/com/android/packageinstaller/permission/ui/auto/AutoAllAppPermissionsFragment.java index c07fe5f..006aec3 100644 --- a/src/com/android/packageinstaller/permission/ui/auto/AutoAllAppPermissionsFragment.java +++ b/src/com/android/packageinstaller/permission/ui/auto/AutoAllAppPermissionsFragment.java
@@ -16,7 +16,6 @@ package com.android.packageinstaller.permission.ui.auto; -import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -41,6 +40,7 @@ import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreference; +import com.android.car.ui.AlertDialogBuilder; import com.android.packageinstaller.auto.AutoSettingsFrameFragment; import com.android.packageinstaller.permission.model.AppPermissionGroup; import com.android.packageinstaller.permission.model.Permission; @@ -251,7 +251,7 @@ final CharSequence desc = perm.loadDescription(pm); pref.setOnPreferenceClickListener((Preference preference) -> { - new AlertDialog.Builder(getContext()) + new AlertDialogBuilder(getContext()) .setMessage(desc) .setPositiveButton(android.R.string.ok, /* listener= */ null) .show();
diff --git a/src/com/android/packageinstaller/permission/ui/auto/AutoAppPermissionFragment.java b/src/com/android/packageinstaller/permission/ui/auto/AutoAppPermissionFragment.java index ecbde6c..1ff7c76 100644 --- a/src/com/android/packageinstaller/permission/ui/auto/AutoAppPermissionFragment.java +++ b/src/com/android/packageinstaller/permission/ui/auto/AutoAppPermissionFragment.java
@@ -19,7 +19,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.app.Activity; -import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.Intent; @@ -43,6 +42,7 @@ import androidx.preference.PreferenceScreen; import androidx.preference.TwoStatePreference; +import com.android.car.ui.AlertDialogBuilder; import com.android.packageinstaller.auto.AutoSettingsFrameFragment; import com.android.packageinstaller.permission.model.AppPermissionGroup; import com.android.packageinstaller.permission.model.Permission; @@ -772,15 +772,14 @@ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AutoAppPermissionFragment fragment = (AutoAppPermissionFragment) getTargetFragment(); - AlertDialog.Builder b = new AlertDialog.Builder(getContext()) + return new AlertDialogBuilder(getContext()) .setMessage(getArguments().getInt(MSG)) .setNegativeButton(R.string.cancel, (dialog, which) -> fragment.updateUi()) .setPositiveButton(R.string.grant_dialog_button_deny_anyway, (dialog, which) -> - fragment.onDenyAnyWay(getArguments().getInt(CHANGE_TARGET))); - - return b.create(); + fragment.onDenyAnyWay(getArguments().getInt(CHANGE_TARGET))) + .create(); } }