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

Commit 6688a359 authored by Carmen Agimof's avatar Carmen Agimof
Browse files

Add new pushed atom to log when an app is installed on external storage.

Change-Id: I998a64bf02c0bf97938396ff12e3ded2e2ac043d
Bug: 123688171
Test: Manually tested using statsd_testdrive script.
parent d55e1b17
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import "frameworks/base/core/proto/android/stats/docsui/docsui_enums.proto";
import "frameworks/base/core/proto/android/stats/devicepolicy/device_policy.proto";
import "frameworks/base/core/proto/android/stats/devicepolicy/device_policy_enums.proto";
import "frameworks/base/core/proto/android/stats/launcher/launcher.proto";
import "frameworks/base/core/proto/android/stats/storage/storage_enums.proto";
import "frameworks/base/core/proto/android/stats/style/style_enums.proto";
import "frameworks/base/core/proto/android/telecomm/enums.proto";
import "frameworks/base/core/proto/android/telephony/enums.proto";
@@ -250,6 +251,7 @@ message Atom {
        HiddenApiUsed hidden_api_used = 178 [(allow_from_any_uid) = true];
        StyleUIChanged style_ui_changed = 179;
        PrivacyIndicatorsInteracted privacy_indicators_interacted = 180;
        AppInstallOnExternalStorageReported app_install_on_external_storage_reported = 181;
    }

    // Pulled events will start at field 10000.
@@ -2556,6 +2558,18 @@ message AppOptimizedAfterDowngraded {
    optional string package_name = 1;
}

/**
 * Logs whenever an app is installed on external storage.
 * Logged from:
        frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java
 */
message AppInstallOnExternalStorageReported {
    // The type of external storage.
    optional android.stats.storage.ExternalStorageType storage_type = 1;
    // The name of the package that is installed on the sd card.
    optional string package_name = 2;
}

/**
 * Logs when an app crashes.
 * Logged from:
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

syntax = "proto2";

package android.stats.storage;

enum ExternalStorageType {
  UNKNOWN = 0;
  SD_CARD = 1;
  USB = 2;
  OTHER = 3;
}
+39 −1
Original line number Diff line number Diff line
@@ -160,9 +160,9 @@ import android.content.pm.InstantAppInfo;
import android.content.pm.InstantAppRequest;
import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.PackageBackwardCompatibility;
import android.content.pm.KeySet;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageBackwardCompatibility;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfoLite;
import android.content.pm.PackageInstaller;
@@ -232,6 +232,7 @@ import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManagerInternal;
import android.os.storage.DiskInfo;
import android.os.storage.IStorageManager;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
@@ -245,6 +246,7 @@ import android.provider.Settings.Secure;
import android.security.KeyStore;
import android.security.SystemKeyStore;
import android.service.pm.PackageServiceDumpProto;
import android.stats.storage.StorageEnums;
import android.system.ErrnoException;
import android.system.Os;
import android.text.TextUtils;
@@ -269,6 +271,7 @@ import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
import android.util.SparseIntArray;
import android.util.StatsLog;
import android.util.TimingsTraceLog;
import android.util.Xml;
import android.util.jar.StrictJarFile;
@@ -1912,6 +1915,15 @@ public class PackageManagerService extends IPackageManager.Stub
                // Send broadcast package appeared if external for all users
                if (isExternal(res.pkg)) {
                    if (!update) {
                        int packageExternalStorageType =
                                getPackageExternalStorageType(res.pkg);
                        // If the package was installed externally, log it.
                        if (packageExternalStorageType != StorageEnums.UNKNOWN) {
                            StatsLog.write(StatsLog.APP_INSTALL_ON_EXTERNAL_STORAGE_REPORTED,
                                    packageExternalStorageType, res.pkg.packageName);
                        }
                    }
                    if (DEBUG_INSTALL) {
                        Slog.i(TAG, "upgrading pkg " + res.pkg + " is external");
                    }
@@ -2000,6 +2012,32 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    /**
     * Gets the type of the external storage a package is installed on.
     * @param pkg The package for which to get the external storage type.
     * @return {@link StorageEnum#TYPE_UNKNOWN} if it is not stored externally or the corresponding
     * {@link StorageEnum} storage type value if it is.
     */
    private int getPackageExternalStorageType(PackageParser.Package pkg) {
        final StorageManager storage = mContext.getSystemService(StorageManager.class);
        VolumeInfo volume = storage.findVolumeByUuid(pkg.applicationInfo.storageUuid.toString());
        if (volume != null) {
            DiskInfo disk = volume.getDisk();
            if (disk != null) {
                if (disk.isSd()) {
                    return StorageEnums.SD_CARD;
                }
                if (disk.isUsb()) {
                    return StorageEnums.USB;
                }
                if (isExternal(pkg)) {
                    return StorageEnums.OTHER;
                }
            }
        }
        return StorageEnums.UNKNOWN;
    }
    private StorageEventListener mStorageListener = new StorageEventListener() {
        @Override
        public void onVolumeStateChanged(VolumeInfo vol, int oldState, int newState) {