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