1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.adservices.ui.settings.activities; 17 18 import static com.android.adservices.ui.UxUtil.isUxStatesReady; 19 20 import android.content.Context; 21 import android.os.Build; 22 import android.os.Bundle; 23 import android.view.MenuItem; 24 25 import androidx.annotation.RequiresApi; 26 import androidx.core.view.WindowCompat; 27 28 import com.android.adservices.service.FlagsFactory; 29 import com.android.adservices.ui.OTAResourcesManager; 30 import com.android.adservices.ui.UxSelector; 31 import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity; 32 33 /** 34 * Android application activity for controlling settings related to PP (Privacy Preserving) APIs. 35 * This class is the base class for all other activities. We need an activity for each page in order 36 * for {@link CollapsingToolbarBaseActivity} to work properly. 37 */ 38 // TODO(b/269798827): Enable for R. 39 @RequiresApi(Build.VERSION_CODES.S) 40 public abstract class AdServicesBaseActivity extends CollapsingToolbarBaseActivity 41 implements UxSelector { 42 private UxSelector.EndUserUx mCurUx; 43 44 @Override onCreate(Bundle savedInstanceState)45 protected void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 Context context = getApplicationContext(); 49 WindowCompat.setDecorFitsSystemWindows(getWindow(), false); 50 51 if (FlagsFactory.getFlags().getUiOtaStringsFeatureEnabled() 52 || FlagsFactory.getFlags().getUiOtaResourcesFeatureEnabled()) { 53 OTAResourcesManager.applyOTAResources(context, false); 54 } 55 if (isUxStatesReady(this)) { 56 mCurUx = initWithUx(this, context); 57 } 58 } 59 60 @Override onResume()61 protected void onResume() { 62 super.onResume(); 63 // if the intended UX is different from the current UX, then recreate activity to update. 64 // This may happen due to non-process stable changes such as PAS notification recorded as 65 // displayed in ConsentManager, which requires an updated UX to be displayed. 66 if (isUxStatesReady(this) && getEndUserUx(this) != mCurUx) { 67 recreate(); 68 } 69 } 70 71 @Override initGaUxWithPas()72 public void initGaUxWithPas() { 73 // overriding in base activity since PAS layout will be the same as GA. 74 initGA(); 75 } 76 77 @Override onOptionsItemSelected(MenuItem item)78 public boolean onOptionsItemSelected(MenuItem item) { 79 if (item.getItemId() == android.R.id.home) { 80 onBackPressed(); 81 return true; 82 } 83 return super.onOptionsItemSelected(item); 84 } 85 } 86