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

Commit a03a2914 authored by Mario Bertschler's avatar Mario Bertschler Committed by Android (Google) Code Review
Browse files

Merge "App Widget Service with dump in protobuf format"

parents 48a9e264 86882f45
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ option java_multiple_files = true;
option java_outer_classname = "IncidentProtoMetadata";

import "frameworks/base/libs/incident/proto/android/privacy.proto";
import "frameworks/base/core/proto/android/service/appwidget.proto";
import "frameworks/base/core/proto/android/service/fingerprint.proto";
import "frameworks/base/core/proto/android/service/netstats.proto";
import "frameworks/base/core/proto/android/providers/settings.proto";
@@ -53,4 +54,5 @@ message IncidentProto {
    android.service.fingerprint.FingerprintServiceDumpProto fingerprint = 3000;
    android.service.NetworkStatsServiceDumpProto netstats = 3001;
    android.providers.settings.SettingsServiceDumpProto settings = 3002;
    android.service.appwidget.AppWidgetServiceDumpProto appwidget = 3003;
}
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 = "proto3";

package android.service.appwidget;

option java_multiple_files = true;
option java_outer_classname = "AppWidgetServiceProto";

// represents the object holding the dump info of the app widget service
message AppWidgetServiceDumpProto {
  repeated WidgetProto widgets = 1; // the array of bound widgets
}

// represents a bound widget
message WidgetProto {
  bool isCrossProfile = 1; // true if host and provider belong to diff users
  bool isHostStopped = 2; // true if host has not called startListening yet
  string hostPackage = 3;
  string providerPackage = 4;
  string providerClass = 5;
  int32 minWidth = 6;
  int32 minHeight = 7;
  int32 maxWidth = 8;
  int32 maxHeight = 9;
}
+70 −23
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.service.appwidget.AppWidgetServiceDumpProto;
import android.service.appwidget.WidgetProto;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.AtomicFile;
@@ -83,6 +85,7 @@ import android.util.SparseIntArray;
import android.util.SparseLongArray;
import android.util.TypedValue;
import android.util.Xml;
import android.util.proto.ProtoOutputStream;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
@@ -717,6 +720,52 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
                                                + ", uid=" + Binder.getCallingUid());

        synchronized (mLock) {
            if (args.length > 0 && "--proto".equals(args[0])) {
                dumpProto(fd);
            } else {
                dumpInternal(pw);
            }
        }
    }

    private void dumpProto(FileDescriptor fd) {
        Slog.i(TAG, "dump proto for " + mWidgets.size() + " widgets");

        ProtoOutputStream proto = new ProtoOutputStream(fd);
        int N = mWidgets.size();
        for (int i=0; i < N; i++) {
            dumpProtoWidget(proto, mWidgets.get(i));
        }
        proto.flush();
    }

    private void dumpProtoWidget(ProtoOutputStream proto, Widget widget) {
        if (widget.host == null || widget.provider == null) {
            Slog.d(TAG, "skip dumping widget because host or provider is null: widget.host="
                + widget.host + " widget.provider="  + widget.provider);
            return;
        }
        long token = proto.start(AppWidgetServiceDumpProto.WIDGETS);
        proto.write(WidgetProto.IS_CROSS_PROFILE,
            widget.host.getUserId() != widget.provider.getUserId());
        proto.write(WidgetProto.IS_HOST_STOPPED, widget.host.callbacks == null);
        proto.write(WidgetProto.HOST_PACKAGE, widget.host.id.packageName);
        proto.write(WidgetProto.PROVIDER_PACKAGE, widget.provider.id.componentName.getPackageName());
        proto.write(WidgetProto.PROVIDER_CLASS, widget.provider.id.componentName.getClassName());
        if (widget.options != null) {
            proto.write(WidgetProto.MIN_WIDTH,
                widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, 0));
            proto.write(WidgetProto.MIN_HEIGHT,
                widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0));
            proto.write(WidgetProto.MAX_WIDTH,
                widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, 0));
            proto.write(WidgetProto.MAX_HEIGHT,
                widget.options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, 0));
        }
        proto.end(token);
    }

    private void dumpInternal(PrintWriter pw) {
        int N = mProviders.size();
        pw.println("Providers:");
        for (int i = 0; i < N; i++) {
@@ -737,7 +786,6 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            dumpHost(mHosts.get(i), i, pw);
        }


        N = mPackagesWithBindWidgetPermission.size();
        pw.println(" ");
        pw.println("Grants:");
@@ -746,7 +794,6 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
            dumpGrant(grant, i, pw);
        }
    }
    }

    @Override
    public ParceledListSlice<PendingHostUpdate> startListening(IAppWidgetHost callbacks,