• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 
17 package com.android.settings.deviceinfo;
18 
19 import android.app.ActivityManager;
20 import android.app.settings.SettingsEnums;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.os.UserManager;
24 import android.os.storage.DiskInfo;
25 import android.os.storage.VolumeInfo;
26 import android.view.View;
27 import android.widget.Button;
28 
29 import com.android.settings.R;
30 import com.android.settings.overlay.FeatureFactory;
31 
32 public class StorageWizardInit extends StorageWizardBase {
33     private Button mInternal;
34 
35     private boolean mIsPermittedToAdopt;
36 
37     @Override
onCreate(Bundle savedInstanceState)38     protected void onCreate(Bundle savedInstanceState) {
39         super.onCreate(savedInstanceState);
40         if (mDisk == null) {
41             finish();
42             return;
43         }
44         setContentView(R.layout.storage_wizard_init);
45 
46         mIsPermittedToAdopt = UserManager.get(this).isAdminUser()
47                 && !ActivityManager.isUserAMonkey();
48 
49         setHeaderText(R.string.storage_wizard_init_v2_title, getDiskShortDescription());
50 
51         mInternal = requireViewById(R.id.storage_wizard_init_internal);
52 
53         setBackButtonText(R.string.storage_wizard_init_v2_later);
54         setNextButtonVisibility(View.INVISIBLE);
55         if (!mDisk.isAdoptable()) {
56             // If not adoptable, we only have one choice
57             mInternal.setEnabled(false);
58             onNavigateExternal(null);
59         } else if (!mIsPermittedToAdopt) {
60             // TODO: Show a message about why this is disabled for guest and
61             // that only an admin user can adopt an sd card.
62             mInternal.setEnabled(false);
63         }
64     }
65 
66     @Override
onNavigateBack(View view)67     public void onNavigateBack(View view) {
68         finish();
69     }
70 
onNavigateExternal(View view)71     public void onNavigateExternal(View view) {
72         if (view != null) {
73             // User made an explicit choice for external
74             FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
75                     SettingsEnums.ACTION_STORAGE_INIT_EXTERNAL);
76         }
77 
78         if (mVolume != null && mVolume.getType() == VolumeInfo.TYPE_PUBLIC
79                 && mVolume.getState() != VolumeInfo.STATE_UNMOUNTABLE) {
80             // Remember that user made decision
81             mStorage.setVolumeInited(mVolume.getFsUuid(), true);
82 
83             final Intent intent = new Intent(this, StorageWizardReady.class);
84             intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
85             startActivity(intent);
86             finish();
87 
88         } else {
89             // Gotta format to get there
90             StorageWizardFormatConfirm.showPublic(this, mDisk.getId());
91         }
92     }
93 
onNavigateInternal(View view)94     public void onNavigateInternal(View view) {
95         if (view != null) {
96             // User made an explicit choice for internal
97             FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
98                     SettingsEnums.ACTION_STORAGE_INIT_INTERNAL);
99         }
100 
101         StorageWizardFormatConfirm.showPrivate(this, mDisk.getId());
102     }
103 }
104