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

Commit 7b532b73 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "startop: Add iorap parcelables for AIDL interfaces"

parents 3b12359e ca4fee19
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
// Copyright (C) 2018 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.

java_library_static {
  name: "libiorap-java",

  aidl: {
    include_dirs: [
      "system/iorap/binder",
    ],
  },

  srcs: [
      ":iorap-aidl",
      "**/*.java",
  ],
}

android_test {
    name: "libiorap-java-tests",
    srcs: ["tests/src/**/*.kt"],

    static_libs: [
      // non-test dependencies
      "libiorap-java",
      // test android dependencies
      "platform-test-annotations",
      "android-support-test",
      // test framework dependencies
      "mockito-target-inline-minus-junit4",
      "truth-prebuilt",
    ],

    //sdk_version: "current",
    //certificate: "platform",

    libs: ["android.test.base"],

    test_suites: ["device-tests"],
}
+31 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 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.
-->
<!--suppress AndroidUnknownAttribute -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.android.startop.iorap.tests"
    android:sharedUserId="com.google.android.startop.iorap.tests"
    android:versionCode="1"
    android:versionName="1.0" >

    <!--suppress AndroidDomInspection -->
    <instrumentation
        android:name="android.support.test.runner.AndroidJUnitRunner"
        android:targetPackage="com.google.android.startop.iorap.tests" />

    <application>
        <uses-library android:name="android.test.runner" />
    </application>
</manifest>
+139 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

package com.google.android.startop.iorap;

import android.os.Parcelable;
import android.os.Parcel;

import android.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * Provide a hint to iorapd that an activity has transitioned state.<br /><br />
 *
 * Knowledge of when an activity starts/stops can be used by iorapd to increase system
 * performance (e.g. by launching perfetto tracing to record an io profile, or by
 * playing back an ioprofile via readahead) over the long run.<br /><br />
 *
 * /@see com.google.android.startop.iorap.IIorap#onActivityHintEvent<br /><br />
 *
 * Once an activity hint is in {@link #TYPE_STARTED} it must transition to another type.
 * All other states could be terminal, see below: <br /><br />
 *
 * <pre>
 *
 *          ┌──────────────────────────────────────┐
 *          │                                      ▼
 *        ┌─────────┐     ╔════════════════╗     ╔═══════════╗
 *    ──▶ │ STARTED │ ──▶ ║   COMPLETED    ║ ──▶ ║ CANCELLED ║
 *        └─────────┘     ╚════════════════╝     ╚═══════════╝
 *                          │
 *                          │
 *                          ▼
 *                        ╔════════════════╗
 *                        ║ POST_COMPLETED ║
 *                        ╚════════════════╝
 *
 * </pre> <!-- system/iorap/docs/binder/ActivityHint.dot -->
 *
 * @hide
 */
public class ActivityHintEvent implements Parcelable {

    public static final int TYPE_STARTED = 0;
    public static final int TYPE_CANCELLED = 1;
    public static final int TYPE_COMPLETED = 2;
    public static final int TYPE_POST_COMPLETED = 3;
    private static final int TYPE_MAX = TYPE_POST_COMPLETED;

    /** @hide */
    @IntDef(flag = true, prefix = { "TYPE_" }, value = {
            TYPE_STARTED,
            TYPE_CANCELLED,
            TYPE_COMPLETED,
            TYPE_POST_COMPLETED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type {}

    @Type public final int type;
    public final ActivityInfo activityInfo;

    public ActivityHintEvent(@Type int type, ActivityInfo activityInfo) {
        this.type = type;
        this.activityInfo = activityInfo;
        checkConstructorArguments();
    }

    private void checkConstructorArguments() {
        CheckHelpers.checkTypeInRange(type, TYPE_MAX);
        Objects.requireNonNull(activityInfo, "activityInfo");
    }

    @Override
    public String toString() {
        return String.format("{type: %d, activityInfo: %s}", type, activityInfo);
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        } else if (other instanceof ActivityHintEvent) {
            return equals((ActivityHintEvent) other);
        }
        return false;
    }

    private boolean equals(ActivityHintEvent other) {
        return type == other.type &&
                Objects.equals(activityInfo, other.activityInfo);
    }

    //<editor-fold desc="Binder boilerplate">
    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(type);
        activityInfo.writeToParcel(out, flags);
    }

    private ActivityHintEvent(Parcel in) {
        this.type = in.readInt();
        this.activityInfo = ActivityInfo.CREATOR.createFromParcel(in);
        checkConstructorArguments();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Parcelable.Creator<ActivityHintEvent> CREATOR
            = new Parcelable.Creator<ActivityHintEvent>() {
        public ActivityHintEvent createFromParcel(Parcel in) {
            return new ActivityHintEvent(in);
        }

        public ActivityHintEvent[] newArray(int size) {
            return new ActivityHintEvent[size];
        }
    };
    //</editor-fold>
}
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

package com.google.android.startop.iorap;

import java.util.Objects;

import android.os.Parcelable;
import android.os.Parcel;

/**
 * Provide minimal information for launched activities to iorap.<br /><br />
 *
 * This uniquely identifies a system-wide activity by providing the {@link #packageName} and
 * {@link #activityName}.
 *
 * @see ActivityHintEvent
 * @see AppIntentEvent
 *
 * @hide
 */
public class ActivityInfo implements Parcelable {

    /** The name of the package, for example {@code com.android.calculator}. */
    public final String packageName;
    /** The name of the activity, for example {@code .activities.activity.MainActivity} */
    public final String activityName;

    public ActivityInfo(String packageName, String activityName) {
        this.packageName = packageName;
        this.activityName = activityName;

        checkConstructorArguments();
    }

    private void checkConstructorArguments() {
        Objects.requireNonNull(packageName, "packageName");
        Objects.requireNonNull(activityName, "activityName");
    }

    @Override
    public String toString() {
        return String.format("{packageName: %s, activityName: %s}", packageName, activityName);
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        } else if (other instanceof ActivityInfo) {
            return equals((ActivityInfo) other);
        }
        return false;
    }

    private boolean equals(ActivityInfo other) {
        return Objects.equals(packageName, other.packageName) &&
                Objects.equals(activityName, other.activityName);
    }

    //<editor-fold desc="Binder boilerplate">
    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeString(packageName);
        out.writeString(activityName);
    }

    private ActivityInfo(Parcel in) {
        packageName = in.readString();
        activityName = in.readString();

        checkConstructorArguments();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Parcelable.Creator<ActivityInfo> CREATOR
            = new Parcelable.Creator<ActivityInfo>() {
        public ActivityInfo createFromParcel(Parcel in) {
            return new ActivityInfo(in);
        }

        public ActivityInfo[] newArray(int size) {
            return new ActivityInfo[size];
        }
    };
    //</editor-fold>
}
+138 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

package com.google.android.startop.iorap;

import android.os.Parcelable;
import android.os.Parcel;

import android.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

/**
 * Notifications for iorapd specifying when a system-wide intent defaults change.<br /><br />
 *
 * Intent defaults provide a mechanism for an app to register itself as an automatic handler.
 * For example the camera app might be registered as the default handler for
 * {@link android.provider.MediaStore#INTENT_ACTION_STILL_IMAGE_CAMERA} intent. Subsequently,
 * if an arbitrary other app requests for a still image camera photo to be taken, the system
 * will launch the respective default camera app to be launched to handle that request.<br /><br />
 *
 * In some cases iorapd might need to know default intents, e.g. for boot-time pinning of
 * applications that resolve from the default intent. If the application would now be resolved
 * differently, iorapd would unpin the old application and pin the new application.<br /><br />
 *
 * @hide
 */
public class AppIntentEvent implements Parcelable {

    /** @see android.content.Intent#CATEGORY_DEFAULT */
    public static final int TYPE_DEFAULT_INTENT_CHANGED = 0;
    private static final int TYPE_MAX = 0;

    /** @hide */
    @IntDef(flag = true, prefix = { "TYPE_" }, value = {
            TYPE_DEFAULT_INTENT_CHANGED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type {}

    @Type public final int type;

    public final ActivityInfo oldActivityInfo;
    public final ActivityInfo newActivityInfo;

    // TODO: Probably need the corresponding action here as well.

    public static AppIntentEvent createDefaultIntentChanged(ActivityInfo oldActivityInfo,
            ActivityInfo newActivityInfo) {
        return new AppIntentEvent(TYPE_DEFAULT_INTENT_CHANGED, oldActivityInfo,
                newActivityInfo);
    }

    private AppIntentEvent(@Type int type, ActivityInfo oldActivityInfo,
            ActivityInfo newActivityInfo) {
        this.type = type;
        this.oldActivityInfo = oldActivityInfo;
        this.newActivityInfo = newActivityInfo;

        checkConstructorArguments();
    }

    private void checkConstructorArguments() {
        CheckHelpers.checkTypeInRange(type, TYPE_MAX);
        Objects.requireNonNull(oldActivityInfo, "oldActivityInfo");
        Objects.requireNonNull(oldActivityInfo, "newActivityInfo");
    }

    @Override
    public String toString() {
        return String.format("{oldActivityInfo: %s, newActivityInfo: %s}", oldActivityInfo,
                newActivityInfo);
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        } else if (other instanceof AppIntentEvent) {
            return equals((AppIntentEvent) other);
        }
        return false;
    }

    private boolean equals(AppIntentEvent other) {
        return type == other.type &&
                Objects.equals(oldActivityInfo, other.oldActivityInfo) &&
                Objects.equals(newActivityInfo, other.newActivityInfo);
    }

    //<editor-fold desc="Binder boilerplate">
    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeInt(type);
        oldActivityInfo.writeToParcel(out, flags);
        newActivityInfo.writeToParcel(out, flags);
    }

    private AppIntentEvent(Parcel in) {
        this.type = in.readInt();
        this.oldActivityInfo = ActivityInfo.CREATOR.createFromParcel(in);
        this.newActivityInfo = ActivityInfo.CREATOR.createFromParcel(in);

        checkConstructorArguments();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Parcelable.Creator<AppIntentEvent> CREATOR
            = new Parcelable.Creator<AppIntentEvent>() {
        public AppIntentEvent createFromParcel(Parcel in) {
            return new AppIntentEvent(in);
        }

        public AppIntentEvent[] newArray(int size) {
            return new AppIntentEvent[size];
        }
    };
    //</editor-fold>
}
Loading