StorageWizardMigrateProgress.java revision b997bd989ec68c657a0263f459545dbea50d6de3
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
17package com.android.settings.deviceinfo;
18
19import static android.content.pm.PackageManager.EXTRA_MOVE_ID;
20import static com.android.settings.deviceinfo.StorageSettings.TAG;
21
22import android.content.Context;
23import android.content.Intent;
24import android.content.pm.PackageManager;
25import android.content.pm.PackageManager.MoveCallback;
26import android.os.Bundle;
27import android.os.Handler;
28import android.os.storage.DiskInfo;
29import android.util.Log;
30import android.view.View;
31import android.widget.Toast;
32
33import com.android.settings.R;
34
35public class StorageWizardMigrateProgress extends StorageWizardBase {
36    private static final String ACTION_FINISH_WIZARD = "com.android.systemui.action.FINISH_WIZARD";
37
38    private int mMoveId;
39
40    @Override
41    protected void onCreate(Bundle savedInstanceState) {
42        super.onCreate(savedInstanceState);
43        if (mVolume == null) {
44            finish();
45            return;
46        }
47        setContentView(R.layout.storage_wizard_progress);
48
49        mMoveId = getIntent().getIntExtra(EXTRA_MOVE_ID, -1);
50
51        final String descrip = mStorage.getBestVolumeDescription(mVolume);
52        setIllustrationInternal(true);
53        setHeaderText(R.string.storage_wizard_migrate_progress_title, descrip);
54        setBodyText(R.string.storage_wizard_migrate_details, descrip);
55
56        getNextButton().setVisibility(View.GONE);
57
58        // Register for updates and push through current status
59        getPackageManager().registerMoveCallback(mCallback, new Handler());
60        mCallback.onStatusChanged(mMoveId, getPackageManager().getMoveStatus(mMoveId), -1);
61    }
62
63    private final MoveCallback mCallback = new MoveCallback() {
64        @Override
65        public void onStatusChanged(int moveId, int status, long estMillis) {
66            if (mMoveId != moveId) return;
67
68            final Context context = StorageWizardMigrateProgress.this;
69            if (PackageManager.isMoveStatusFinished(status)) {
70                Log.d(TAG, "Finished with status " + status);
71                if (status == PackageManager.MOVE_SUCCEEDED) {
72                    if (mDisk != null) {
73                        // Kinda lame, but tear down that shiny finished
74                        // notification, since user is still in wizard flow
75                        final Intent finishIntent = new Intent(ACTION_FINISH_WIZARD);
76                        finishIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
77                        sendBroadcast(finishIntent);
78
79                        final Intent intent = new Intent(context, StorageWizardReady.class);
80                        intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
81                        startActivity(intent);
82                    }
83                } else {
84                    Toast.makeText(context, getString(R.string.insufficient_storage),
85                            Toast.LENGTH_LONG).show();
86                }
87                finishAffinity();
88
89            } else {
90                setCurrentProgress(status);
91            }
92        }
93    };
94}
95