Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aec0ee73 authored by Risan's avatar Risan
Browse files

ResetListener in StorageManagerService

Bug: 110380403
Test: Manual test in ARC++, prototyped a way that reset reaches ARC++
service.
Change-Id: Icc7dcc8b5c726ed9f61226569227c4d47f44b386
parent 0ac63d74
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os.storage;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.IVold;

/**
 * Mount service local interface.
@@ -111,4 +112,24 @@ public abstract class StorageManagerInternal {
     * @return Labels of storage volumes that are visible to the given userId.
     */
    public abstract String[] getVisibleVolumesForUser(int userId);

    /**
     * A listener for reset events in the StorageManagerService.
     */
    public interface ResetListener {
        /**
         * A method that should be triggered internally by StorageManagerInternal
         * when StorageManagerService reset happens.
         *
         * @param vold The binder object to vold.
         */
        void onReset(IVold vold);
    }

    /**
     * Add a listener to listen to reset event in StorageManagerService.
     *
     * @param listener The listener that will be notified on reset events.
     */
    public abstract void addResetListener(ResetListener listener);
}
+20 −0
Original line number Diff line number Diff line
@@ -878,6 +878,7 @@ class StorageManagerService extends IStorageManager.Stub
                    mStoraged.onUserStarted(userId);
                }
                mVold.onSecureKeyguardStateChanged(mSecureKeyguardShowing);
                mStorageManagerInternal.onReset(mVold);
            } catch (Exception e) {
                Slog.wtf(TAG, e);
            }
@@ -3635,6 +3636,10 @@ class StorageManagerService extends IStorageManager.Stub
        private final CopyOnWriteArrayList<ExternalStorageMountPolicy> mPolicies =
                new CopyOnWriteArrayList<>();

        @GuardedBy("mResetListeners")
        private final List<StorageManagerInternal.ResetListener> mResetListeners =
                new ArrayList<>();

        @Override
        public void addExternalStoragePolicy(ExternalStorageMountPolicy policy) {
            // No locking - CopyOnWriteArrayList
@@ -3666,6 +3671,21 @@ class StorageManagerService extends IStorageManager.Stub
            return mountMode;
        }

        @Override
        public void addResetListener(StorageManagerInternal.ResetListener listener) {
            synchronized (mResetListeners) {
                mResetListeners.add(listener);
            }
        }

        public void onReset(IVold vold) {
            synchronized (mResetListeners) {
                for (StorageManagerInternal.ResetListener listener : mResetListeners) {
                    listener.onReset(vold);
                }
            }
        }

        public boolean hasExternalStorage(int uid, String packageName) {
            // No need to check for system uid. This avoids a deadlock between
            // PackageManagerService and AppOpsService.