• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.os.Build;
19 import android.os.Bundle;
20 
21 import androidx.annotation.RequiresApi;
22 import androidx.lifecycle.ViewModelProvider;
23 
24 import com.android.adservices.api.R;
25 import com.android.adservices.service.FlagsFactory;
26 import com.android.adservices.service.stats.UiStatsLogger;
27 import com.android.adservices.ui.OTAResourcesManager;
28 import com.android.adservices.ui.settings.activitydelegates.MainActivityActionDelegate;
29 import com.android.adservices.ui.settings.delegates.MainActionDelegate;
30 import com.android.adservices.ui.settings.fragments.AdServicesSettingsMainFragment;
31 import com.android.adservices.ui.settings.viewmodels.MainViewModel;
32 
33 /**
34  * Android application activity for controlling settings related to PP (Privacy Preserving) APIs.
35  */
36 // TODO(b/269798827): Enable for R.
37 @RequiresApi(Build.VERSION_CODES.S)
38 public class AdServicesSettingsMainActivity extends AdServicesBaseActivity {
39     public static final String FROM_NOTIFICATION_KEY = "FROM_NOTIFICATION";
40     private MainActionDelegate mActionDelegate;
41 
42     /** @return the action delegate for the activity. */
getActionDelegate()43     public MainActionDelegate getActionDelegate() {
44         return mActionDelegate;
45     }
46 
47     @Override
onBackPressed()48     public void onBackPressed() {
49         // if navigated here from notification, then back button should not go back to notification.
50         if (getIntent().getBooleanExtra(FROM_NOTIFICATION_KEY, false)) {
51             moveTaskToBack(true);
52         } else {
53             super.onBackPressed();
54         }
55     }
56 
57     @Override
onCreate(Bundle savedInstanceState)58     protected void onCreate(Bundle savedInstanceState) {
59         // Only for main view, we want to use the most up to date OTA strings on the device to
60         // create the ResourcesLoader.
61         if (FlagsFactory.getFlags().getUiOtaStringsFeatureEnabled()) {
62             OTAResourcesManager.applyOTAResources(getApplicationContext(), true);
63         }
64         UiStatsLogger.logSettingsPageDisplayed(getApplication());
65         super.onCreate(savedInstanceState);
66         if (!FlagsFactory.getFlags().getU18UxEnabled()) {
67             initMainFragment();
68         }
69     }
70 
initMainFragment()71     private void initMainFragment() {
72         setContentView(R.layout.adservices_settings_main_activity);
73         getSupportFragmentManager()
74                 .beginTransaction()
75                 .replace(R.id.fragment_container_view, AdServicesSettingsMainFragment.class, null)
76                 .setReorderingAllowed(true)
77                 .commit();
78         mActionDelegate =
79                 new MainActionDelegate(this, new ViewModelProvider(this).get(MainViewModel.class));
80     }
81 
82     @Override
onResume()83     protected void onResume() {
84         super.onResume();
85         if (FlagsFactory.getFlags().getU18UxEnabled()) {
86             initWithMode(true);
87         }
88     }
89 
90     @Override
initBeta()91     public void initBeta() {
92         initMainActivity();
93     }
94 
95     @Override
initGA()96     public void initGA() {
97         initMainActivity();
98     }
99 
100     @Override
initU18()101     public void initU18() {}
102 
initMainActivity()103     private void initMainActivity() {
104         setContentView(R.layout.main_activity);
105         // no need to store since no
106         new MainActivityActionDelegate(this, new ViewModelProvider(this).get(MainViewModel.class));
107     }
108 }
109