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

Commit 243dd7a2 authored by Andrew Sapperstein's avatar Andrew Sapperstein Committed by Android (Google) Code Review
Browse files

Merge "Define stub and data classes for SharedConnectivity Service"

parents e69aa70e 86e2e4f0
Loading
Loading
Loading
Loading
+127 −0
Original line number Diff line number Diff line
@@ -9783,6 +9783,133 @@ package android.net.wifi.nl80211 {
}
package android.net.wifi.sharedconnectivity.app {
  public final class DeviceInfo implements android.os.Parcelable {
    method public int describeContents();
    method @IntRange(from=0, to=100) @NonNull public int getBatteryPercentage();
    method @IntRange(from=0, to=3) @NonNull public int getConnectionStrength();
    method @NonNull public String getDeviceName();
    method public int getDeviceType();
    method @NonNull public String getModelName();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.DeviceInfo> CREATOR;
    field public static final int DEVICE_TYPE_LAPTOP = 3; // 0x3
    field public static final int DEVICE_TYPE_PHONE = 1; // 0x1
    field public static final int DEVICE_TYPE_TABLET = 2; // 0x2
    field public static final int DEVICE_TYPE_UNKNOWN = 0; // 0x0
  }
  public static final class DeviceInfo.Builder {
    ctor public DeviceInfo.Builder();
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo build();
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo.Builder setBatteryPercentage(@IntRange(from=0, to=100) int);
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo.Builder setConnectionStrength(@IntRange(from=0, to=3) int);
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo.Builder setDeviceName(@NonNull String);
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo.Builder setDeviceType(int);
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo.Builder setModelName(@NonNull String);
  }
  public final class KnownNetwork implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo getDeviceInfo();
    method @NonNull public int getNetworkSource();
    method @NonNull public int[] getSecurityTypes();
    method @NonNull public String getSsid();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.KnownNetwork> CREATOR;
    field public static final int NETWORK_SOURCE_CLOUD_SELF = 1; // 0x1
    field public static final int NETWORK_SOURCE_NEARBY_SELF = 0; // 0x0
  }
  public static final class KnownNetwork.Builder {
    ctor public KnownNetwork.Builder();
    method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork build();
    method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setDeviceInfo(@NonNull android.net.wifi.sharedconnectivity.app.DeviceInfo);
    method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setNetworkSource(int);
    method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setSecurityTypes(@NonNull int[]);
    method @NonNull public android.net.wifi.sharedconnectivity.app.KnownNetwork.Builder setSsid(@NonNull String);
  }
  public interface SharedConnectivityClientCallback {
    method public void onKnownNetworksUpdated(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.KnownNetwork>);
    method public void onSharedConnectivitySettingsChanged(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState);
    method public void onTetherNetworksUpdated(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.TetherNetwork>);
  }
  public class SharedConnectivityManager {
    ctor public SharedConnectivityManager(@NonNull android.content.Context);
    method public boolean connectKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
    method public boolean connectTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
    method public boolean disconnectTetherNetwork();
    method public boolean forgetKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
    method public boolean registerCallback(@NonNull java.util.concurrent.Executor, @NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivityClientCallback);
    method public boolean unregisterCallback(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivityClientCallback);
  }
  public final class SharedConnectivitySettingsState implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.os.Bundle getExtras();
    method @NonNull public boolean isInstantTetherEnabled();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState> CREATOR;
  }
  public static final class SharedConnectivitySettingsState.Builder {
    ctor public SharedConnectivitySettingsState.Builder();
    method @NonNull public android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState build();
    method @NonNull public android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState.Builder setExtras(@NonNull android.os.Bundle);
    method @NonNull public android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState.Builder setInstantTetherEnabled(boolean);
  }
  public final class TetherNetwork implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public long getDeviceId();
    method @NonNull public android.net.wifi.sharedconnectivity.app.DeviceInfo getDeviceInfo();
    method @Nullable public String getHotspotBssid();
    method @Nullable public int[] getHotspotSecurityTypes();
    method @Nullable public String getHotspotSsid();
    method @NonNull public String getNetworkName();
    method @NonNull public int getNetworkType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.sharedconnectivity.app.TetherNetwork> CREATOR;
    field public static final int NETWORK_TYPE_CELLULAR = 1; // 0x1
    field public static final int NETWORK_TYPE_ETHERNET = 3; // 0x3
    field public static final int NETWORK_TYPE_UNKNOWN = 0; // 0x0
    field public static final int NETWORK_TYPE_WIFI = 2; // 0x2
  }
  public static final class TetherNetwork.Builder {
    ctor public TetherNetwork.Builder();
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork build();
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setDeviceId(long);
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setDeviceInfo(@NonNull android.net.wifi.sharedconnectivity.app.DeviceInfo);
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setHotspotBssid(@NonNull String);
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setHotspotSecurityTypes(@NonNull int[]);
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setHotspotSsid(@NonNull String);
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setNetworkName(@NonNull String);
    method @NonNull public android.net.wifi.sharedconnectivity.app.TetherNetwork.Builder setNetworkType(int);
  }
}
package android.net.wifi.sharedconnectivity.service {
  public abstract class SharedConnectivityService extends android.app.Service {
    ctor public SharedConnectivityService();
    ctor public SharedConnectivityService(@NonNull android.os.Handler);
    method @Nullable public android.os.IBinder onBind(@NonNull android.content.Intent);
    method public abstract void onConnectKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
    method public abstract void onConnectTetherNetwork(@NonNull android.net.wifi.sharedconnectivity.app.TetherNetwork);
    method public abstract void onDisconnectTetherNetwork();
    method public abstract void onForgetKnownNetwork(@NonNull android.net.wifi.sharedconnectivity.app.KnownNetwork);
    method public final void setKnownNetworks(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.KnownNetwork>);
    method public final void setSettingsState(@NonNull android.net.wifi.sharedconnectivity.app.SharedConnectivitySettingsState);
    method public final void setTetherNetworks(@NonNull java.util.List<android.net.wifi.sharedconnectivity.app.TetherNetwork>);
  }
}
package android.nfc {
  public final class NfcAdapter {
+8 −0
Original line number Diff line number Diff line
@@ -1863,6 +1863,14 @@ package android.net {

}

package android.net.wifi.sharedconnectivity.app {

  public class SharedConnectivityManager {
    method public void setService(@Nullable android.os.IInterface);
  }

}

package android.os {

  public final class BatteryStatsManager {
+4 −1
Original line number Diff line number Diff line
@@ -27,7 +27,10 @@ package {

filegroup {
    name: "framework-wifi-non-updatable-sources-internal",
    srcs: ["src/**/*.java"],
    srcs: [
        "src/**/*.java",
        "src/**/*.aidl",
    ],
    path: "src",
    visibility: ["//visibility:private"],
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.net.wifi.sharedconnectivity.app;

parcelable DeviceInfo;
 No newline at end of file
+299 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.net.wifi.sharedconnectivity.app;

import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.net.wifi.sharedconnectivity.service.SharedConnectivityService;
import android.os.Parcel;
import android.os.Parcelable;

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

/**
 * A data class representing a device providing connectivity.
 * This class is used in IPC calls between the implementer of {@link SharedConnectivityService} and
 * the consumers of {@link com.android.wifitrackerlib}.
 *
 * @hide
 */
@SystemApi
public final class DeviceInfo implements Parcelable {

    /**
     * Device type providing connectivity is unknown.
     */
    public static final int DEVICE_TYPE_UNKNOWN = 0;

    /**
     * Device providing connectivity is a mobile phone.
     */
    public static final int DEVICE_TYPE_PHONE = 1;

    /**
     * Device providing connectivity is a tablet.
     */
    public static final int DEVICE_TYPE_TABLET = 2;

    /**
     * Device providing connectivity is a laptop.
     */
    public static final int DEVICE_TYPE_LAPTOP = 3;

    /**
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            DEVICE_TYPE_UNKNOWN,
            DEVICE_TYPE_PHONE,
            DEVICE_TYPE_TABLET,
            DEVICE_TYPE_LAPTOP
    })
    public @interface DeviceType {}

    @DeviceType private final int mDeviceType;
    private final String mDeviceName;
    private final String mModelName;
    private final int mBatteryPercentage;
    private final int mConnectionStrength;

    /**
     * Builder class for {@link DeviceInfo}.
     */
    public static final class Builder {
        private int mDeviceType;
        private String mDeviceName;
        private String mModelName;
        private int mBatteryPercentage;
        private int mConnectionStrength;

        public Builder() {}

        /**
         * Sets the device type that provides connectivity.
         *
         * @param deviceType Device type as represented by IntDef {@link DeviceType}.
         * @return Returns the Builder object.
         */
        @NonNull
        public Builder setDeviceType(@DeviceType int deviceType) {
            mDeviceType = deviceType;
            return this;
        }

        /**
         * Sets the device name of the remote device.
         *
         * @param deviceName The user configurable device name.
         * @return Returns the Builder object.
         */
        @NonNull
        public Builder setDeviceName(@NonNull String deviceName) {
            mDeviceName = deviceName;
            return this;
        }

        /**
         * Sets the model name of the remote device.
         *
         * @param modelName The OEM configured name for the device model.
         * @return Returns the Builder object.
         */
        @NonNull
        public Builder setModelName(@NonNull String modelName) {
            mModelName = modelName;
            return this;
        }

        /**
         * Sets the battery charge percentage of the remote device.
         *
         * @param batteryPercentage The battery charge percentage in the range 0 to 100.
         * @return Returns the Builder object.
         */
        @NonNull
        public Builder setBatteryPercentage(@IntRange(from = 0, to = 100) int batteryPercentage) {
            mBatteryPercentage = batteryPercentage;
            return this;
        }

        /**
         * Sets the displayed connection strength of the remote device to the internet.
         *
         * @param connectionStrength Connection strength in range 0 to 3.
         * @return Returns the Builder object.
         */
        @NonNull
        public Builder setConnectionStrength(@IntRange(from = 0, to = 3) int connectionStrength) {
            mConnectionStrength = connectionStrength;
            return this;
        }

        /**
         * Builds the {@link DeviceInfo} object.
         *
         * @return Returns the built {@link DeviceInfo} object.
         */
        @NonNull
        public DeviceInfo build() {
            return new DeviceInfo(mDeviceType, mDeviceName, mModelName, mBatteryPercentage,
                    mConnectionStrength);
        }
    }

    private static void validate(int deviceType, String deviceName, String modelName,
            int batteryPercentage, int connectionStrength) {
        if (deviceType != DEVICE_TYPE_UNKNOWN && deviceType != DEVICE_TYPE_PHONE
                && deviceType != DEVICE_TYPE_TABLET && deviceType != DEVICE_TYPE_LAPTOP) {
            throw new IllegalArgumentException("Illegal device type");
        }
        if (Objects.isNull(deviceName)) {
            throw new IllegalArgumentException("DeviceName must be set");
        }
        if (Objects.isNull(modelName)) {
            throw new IllegalArgumentException("ModelName must be set");
        }
        if (batteryPercentage < 0 || batteryPercentage > 100) {
            throw new IllegalArgumentException("BatteryPercentage must be in range 0-100");
        }
        if (connectionStrength < 0 || connectionStrength > 3) {
            throw new IllegalArgumentException("ConnectionStrength must be in range 0-3");
        }
    }

    private DeviceInfo(@DeviceType int deviceType, @NonNull String deviceName,
            @NonNull String modelName, int batteryPercentage, int connectionStrength) {
        validate(deviceType, deviceName, modelName, batteryPercentage, connectionStrength);
        mDeviceType = deviceType;
        mDeviceName = deviceName;
        mModelName = modelName;
        mBatteryPercentage = batteryPercentage;
        mConnectionStrength = connectionStrength;
    }

    /**
     * Gets the device type that provides connectivity.
     *
     * @return Returns the device type as represented by IntDef {@link DeviceType}.
     */
    @DeviceType
    public int getDeviceType() {
        return mDeviceType;
    }

    /**
     * Gets the device name of the remote device.
     *
     * @return Returns the user configurable device name.
     */
    @NonNull
    public String getDeviceName() {
        return mDeviceName;
    }

    /**
     * Gets the model name of the remote device.
     *
     * @return Returns the OEM configured name for the device model.
     */
    @NonNull
    public String getModelName() {
        return mModelName;
    }

    /**
     * Gets the battery charge percentage of the remote device.
     *
     * @return Returns the battery charge percentage in the range 0 to 100.
     */
    @NonNull
    @IntRange(from = 0, to = 100)
    public int getBatteryPercentage() {
        return mBatteryPercentage;
    }

    /**
     * Gets the displayed connection strength of the remote device to the internet.
     *
     * @return Returns the connection strength in range 0 to 3.
     */
    @NonNull
    @IntRange(from = 0, to = 3)
    public int getConnectionStrength() {
        return mConnectionStrength;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof DeviceInfo)) return false;
        DeviceInfo other = (DeviceInfo) obj;
        return mDeviceType == other.getDeviceType()
                && Objects.equals(mDeviceName, other.mDeviceName)
                && Objects.equals(mModelName, other.mModelName)
                && mBatteryPercentage == other.mBatteryPercentage
                && mConnectionStrength == other.mConnectionStrength;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mDeviceType, mDeviceName, mModelName, mBatteryPercentage,
                mConnectionStrength);
    }
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mDeviceType);
        dest.writeString(mDeviceName);
        dest.writeString(mModelName);
        dest.writeInt(mBatteryPercentage);
        dest.writeInt(mConnectionStrength);
    }

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

    @NonNull
    public static final Creator<DeviceInfo> CREATOR = new Creator<DeviceInfo>() {
        @Override
        public DeviceInfo createFromParcel(Parcel in) {
            return new DeviceInfo(in.readInt(), in.readString(), in.readString(), in.readInt(),
                    in.readInt());
        }

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

    @Override
    public String toString() {
        return new StringBuilder("DeviceInfo[")
                .append("deviceType=").append(mDeviceType)
                .append(", deviceName=").append(mDeviceName)
                .append(", modelName=").append(mModelName)
                .append(", batteryPercentage=").append(mBatteryPercentage)
                .append(", connectionStrength=").append(mConnectionStrength)
                .append("]").toString();
    }
}
Loading