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

Commit 723bf37a authored by Fan Zhang's avatar Fan Zhang
Browse files

Initial API for providing suggestions.

This is a WIP system api that will be
 - Implemented by one unbundled app (SettingsIntelligence) using system-sdk,
 - and consumed by Settings app.

Note: The bundled app does not have permission to read/write any
      user settings. Nor does it have permission to call any private API
      to do anything unsafe.

Test: builds
Test: instrumentation test
Bug: 65065268
Change-Id: Ib190c0e4c167deb3c6197b8a5b39d442d804770b
parent ddbc7fb0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -305,6 +305,7 @@ LOCAL_SRC_FILES += \
	core/java/android/service/notification/IStatusBarNotificationHolder.aidl \
	core/java/android/service/notification/IConditionListener.aidl \
	core/java/android/service/notification/IConditionProvider.aidl \
	core/java/android/service/settings/suggestions/ISuggestionService.aidl \
	core/java/android/service/vr/IPersistentVrStateCallbacks.aidl \
	core/java/android/service/vr/IVrListener.aidl \
	core/java/android/service/vr/IVrManager.aidl \
+30 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ package android {
    field public static final java.lang.String BIND_RESOLVER_RANKER_SERVICE = "android.permission.BIND_RESOLVER_RANKER_SERVICE";
    field public static final java.lang.String BIND_RUNTIME_PERMISSION_PRESENTER_SERVICE = "android.permission.BIND_RUNTIME_PERMISSION_PRESENTER_SERVICE";
    field public static final java.lang.String BIND_SCREENING_SERVICE = "android.permission.BIND_SCREENING_SERVICE";
    field public static final java.lang.String BIND_SETTINGS_SUGGESTIONS_SERVICE = "android.permission.BIND_SETTINGS_SUGGESTIONS_SERVICE";
    field public static final java.lang.String BIND_TELECOM_CONNECTION_SERVICE = "android.permission.BIND_TELECOM_CONNECTION_SERVICE";
    field public static final java.lang.String BIND_TEXT_SERVICE = "android.permission.BIND_TEXT_SERVICE";
    field public static final java.lang.String BIND_TRUST_AGENT = "android.permission.BIND_TRUST_AGENT";
@@ -40819,6 +40820,35 @@ package android.service.restrictions {
}
package android.service.settings.suggestions {
  public final class Suggestion implements android.os.Parcelable {
    method public int describeContents();
    method public java.lang.String getId();
    method public android.app.PendingIntent getPendingIntent();
    method public java.lang.CharSequence getSummary();
    method public java.lang.CharSequence getTitle();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.settings.suggestions.Suggestion> CREATOR;
  }
  public static class Suggestion.Builder {
    ctor public Suggestion.Builder(java.lang.String);
    method public android.service.settings.suggestions.Suggestion build();
    method public android.service.settings.suggestions.Suggestion.Builder setPendingIntent(android.app.PendingIntent);
    method public android.service.settings.suggestions.Suggestion.Builder setSummary(java.lang.CharSequence);
    method public android.service.settings.suggestions.Suggestion.Builder setTitle(java.lang.CharSequence);
  }
  public abstract class SuggestionService extends android.app.Service {
    ctor public SuggestionService();
    method public android.os.IBinder onBind(android.content.Intent);
    method public abstract java.util.List<android.service.settings.suggestions.Suggestion> onGetSuggestions();
    method public abstract void onSuggestionDismissed(android.service.settings.suggestions.Suggestion);
  }
}
package android.service.textservice {
  public abstract class SpellCheckerService extends android.app.Service {
+20 −0
Original line number Diff line number Diff line
package android.service.settings.suggestions;

import android.service.settings.suggestions.Suggestion;

import java.util.List;

/** @hide */
interface ISuggestionService {

    /**
     * Return all available suggestions.
     */
    List<Suggestion> getSuggestions() = 1;

    /**
     * Dismiss a suggestion. The suggestion will not be included in future {@link #getSuggestions)
     * calls.
     */
    void dismissSuggestion(in Suggestion suggestion) = 2;
}
 No newline at end of file
+20 −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.
 */

/** @hide */
package android.service.settings.suggestions;

parcelable Suggestion;
+152 −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.
 */

package android.service.settings.suggestions;

import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 * Data object that has information about a device suggestion.
 *
 * @hide
 */
@SystemApi
public final class Suggestion implements Parcelable {

    private final String mId;
    private final CharSequence mTitle;
    private final CharSequence mSummary;
    private final PendingIntent mPendingIntent;

    /**
     * Gets the id for the suggestion object.
     */
    public String getId() {
        return mId;
    }

    /**
     * Title of the suggestion that is shown to the user.
     */
    public CharSequence getTitle() {
        return mTitle;
    }

    /**
     * Optional summary describing what this suggestion controls.
     */
    public CharSequence getSummary() {
        return mSummary;
    }

    /**
     * The Intent to launch when the suggestion is activated.
     */
    public PendingIntent getPendingIntent() {
        return mPendingIntent;
    }

    private Suggestion(Builder builder) {
        mId = builder.mId;
        mTitle = builder.mTitle;
        mSummary = builder.mSummary;
        mPendingIntent = builder.mPendingIntent;
    }

    private Suggestion(Parcel in) {
        mId = in.readString();
        mTitle = in.readCharSequence();
        mSummary = in.readCharSequence();
        mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader());
    }

    public static final Creator<Suggestion> CREATOR = new Creator<Suggestion>() {
        @Override
        public Suggestion createFromParcel(Parcel in) {
            return new Suggestion(in);
        }

        @Override
        public Suggestion[] newArray(int size) {
            return new Suggestion[size];
        }
    };

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(mId);
        dest.writeCharSequence(mTitle);
        dest.writeCharSequence(mSummary);
        dest.writeParcelable(mPendingIntent, flags);
    }

    /**
     * Builder class for {@link Suggestion}.
     */
    public static class Builder {
        private final String mId;
        private CharSequence mTitle;
        private CharSequence mSummary;
        private PendingIntent mPendingIntent;

        public Builder(String id) {
            if (TextUtils.isEmpty(id)) {
                throw new IllegalArgumentException("Suggestion id cannot be empty");
            }
            mId = id;
        }

        /**
         * Sets suggestion title
         */
        public Builder setTitle(CharSequence title) {
            mTitle = title;
            return this;
        }

        /**
         * Sets suggestion summary
         */
        public Builder setSummary(CharSequence summary) {
            mSummary = summary;
            return this;
        }

        /**
         * Sets suggestion intent
         */
        public Builder setPendingIntent(PendingIntent pendingIntent) {
            mPendingIntent = pendingIntent;
            return this;
        }

        /**
         * Builds an immutable {@link Suggestion} object.
         */
        public Suggestion build() {
            return new Suggestion(this /* builder */);
        }
    }
}
Loading