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

Commit 9dc9affb authored by Roshan Pius's avatar Roshan Pius
Browse files

Add WifiOemConfigStoreMigrationHook class for OEM migration

Add a helper class (not part of the wifi mainline module) to migrate
config store data from existing OEM devices. This will be used when the
device upgrades from a build containing OEM impl of wifi to a
build containing wifi mainline module. OEM should implement this
class if they had any non-AOSP changes in the config store
format/field names on their devices.

Bug: 142394776
Test: Compiles
Change-Id: Ie11e0ffe8e4b8f1edcaa23d35284c3b564dc97f4
parent 6769c541
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -6173,6 +6173,25 @@ package android.net.wifi {
    method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_CARRIER_PROVISIONING) public android.net.wifi.WifiNetworkSuggestion.Builder setCarrierId(int);
  }
  public final class WifiOemConfigStoreMigrationHook {
    method @Nullable public static android.net.wifi.WifiOemConfigStoreMigrationHook.MigrationData load();
  }
  public static final class WifiOemConfigStoreMigrationHook.MigrationData implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public java.util.List<android.net.wifi.WifiConfiguration> getUserSavedNetworkConfigurations();
    method @Nullable public android.net.wifi.SoftApConfiguration getUserSoftApConfiguration();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.wifi.WifiOemConfigStoreMigrationHook.MigrationData> CREATOR;
  }
  public static final class WifiOemConfigStoreMigrationHook.MigrationData.Builder {
    ctor public WifiOemConfigStoreMigrationHook.MigrationData.Builder();
    method @NonNull public android.net.wifi.WifiOemConfigStoreMigrationHook.MigrationData build();
    method @NonNull public android.net.wifi.WifiOemConfigStoreMigrationHook.MigrationData.Builder setUserSavedNetworkConfigurations(@NonNull java.util.List<android.net.wifi.WifiConfiguration>);
    method @NonNull public android.net.wifi.WifiOemConfigStoreMigrationHook.MigrationData.Builder setUserSoftApConfiguration(@NonNull android.net.wifi.SoftApConfiguration);
  }
  public class WifiScanner {
    method @Deprecated public void configureWifiChange(int, int, int, int, int, android.net.wifi.WifiScanner.BssidInfo[]);
    method @Deprecated public void configureWifiChange(android.net.wifi.WifiScanner.WifiChangeSettings);
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ filegroup {
        // framework-wifi.jar. This is not a good idea, should move WifiNetworkScoreCache
        // to a separate package.
        "java/android/net/wifi/WifiNetworkScoreCache.java",
        "java/android/net/wifi/WifiOemConfigStoreMigrationHook.java",
        "java/android/net/wifi/wificond/*.java",
        ":libwificond_ipc_aidl",
    ],
+180 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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;

import static com.android.internal.util.Preconditions.checkNotNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;

import java.util.List;

/**
 * Class used to provide one time hooks for existing OEM devices to migrate their config store
 * data to the wifi mainline module.
 * <p>
 * Note:
 * <li> OEM's need to implement {@link #load()} only if their
 * existing config store format or file locations differs from the vanilla AOSP implementation (
 * which is what the wifi mainline module understands).
 * </li>
 * <li> The wifi mainline module will invoke {@link #load()}  method on every bootup, its
 * the responsibility of the OEM implementation to ensure that this method returns non-null data
 * only on the first bootup. Once the migration is done, the OEM can safely delete their config
 * store files and then return null on any subsequent reboots. The first & only relevant invocation
 * of {@link #load()} occurs when a previously released device upgrades to the wifi
 * mainline module from an OEM implementation of the wifi stack.
 * </li>
 * @hide
 */
@SystemApi
public final class WifiOemConfigStoreMigrationHook {
    /**
     * Container for all the wifi config data to migrate.
     */
    public static final class MigrationData implements Parcelable {
        /**
         * Builder to create instance of {@link MigrationData}.
         */
        public static final class Builder {
            private List<WifiConfiguration> mUserSavedNetworkConfigurations;
            private SoftApConfiguration mUserSoftApConfiguration;

            public Builder() {
                mUserSavedNetworkConfigurations = null;
                mUserSoftApConfiguration = null;
            }

            /**
             * Sets the list of all user's saved network configurations parsed from OEM config
             * store files.
             *
             * @param userSavedNetworkConfigurations List of {@link WifiConfiguration} representing
             *                                       the list of user's saved networks
             * @return Instance of {@link Builder} to enable chaining of the builder method.
             */
            public @NonNull Builder setUserSavedNetworkConfigurations(
                    @NonNull List<WifiConfiguration> userSavedNetworkConfigurations) {
                checkNotNull(userSavedNetworkConfigurations);
                mUserSavedNetworkConfigurations = userSavedNetworkConfigurations;
                return this;
            }

            /**
             * Sets the user's softap configuration parsed from OEM config store files.
             *
             * @param userSoftApConfiguration {@link SoftApConfiguration} representing user's
             *                                SoftAp configuration
             * @return Instance of {@link Builder} to enable chaining of the builder method.
             */
            public @NonNull Builder setUserSoftApConfiguration(
                    @NonNull SoftApConfiguration userSoftApConfiguration) {
                checkNotNull(userSoftApConfiguration);
                mUserSoftApConfiguration  = userSoftApConfiguration;
                return this;
            }

            /**
             * Build an instance of {@link MigrationData}.
             *
             * @return Instance of {@link MigrationData}.
             */
            public @NonNull MigrationData build() {
                return new MigrationData(mUserSavedNetworkConfigurations, mUserSoftApConfiguration);
            }
        }

        private final List<WifiConfiguration> mUserSavedNetworkConfigurations;
        private final SoftApConfiguration mUserSoftApConfiguration;

        private MigrationData(
                @Nullable List<WifiConfiguration> userSavedNetworkConfigurations,
                @Nullable SoftApConfiguration userSoftApConfiguration) {
            mUserSavedNetworkConfigurations = userSavedNetworkConfigurations;
            mUserSoftApConfiguration = userSoftApConfiguration;
        }

        public static final @NonNull Parcelable.Creator<MigrationData> CREATOR =
                new Parcelable.Creator<MigrationData>() {
                    @Override
                    public MigrationData createFromParcel(Parcel in) {
                        List<WifiConfiguration> userSavedNetworkConfigurations =
                                in.readArrayList(null);
                        SoftApConfiguration userSoftApConfiguration = in.readParcelable(null);
                        return new MigrationData(
                                userSavedNetworkConfigurations, userSoftApConfiguration);
                    }

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

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

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeList(mUserSavedNetworkConfigurations);
            dest.writeParcelable(mUserSoftApConfiguration, flags);
        }

        /**
         * Returns list of all user's saved network configurations.
         *
         * Note: Only to be returned if there is any format change in how OEM persisted this info.
         * @return List of {@link WifiConfiguration} representing the list of user's saved networks,
         * or null if no migration necessary.
         */
        @Nullable
        public List<WifiConfiguration> getUserSavedNetworkConfigurations() {
            return mUserSavedNetworkConfigurations;
        }

        /**
         * Returns user's softap configuration.
         *
         * Note: Only to be returned if there is any format change in how OEM persisted this info.
         * @return {@link SoftApConfiguration} representing user's SoftAp configuration,
         * or null if no migration necessary.
         */
        @Nullable
        public SoftApConfiguration getUserSoftApConfiguration() {
            return mUserSoftApConfiguration;
        }
    }

    private WifiOemConfigStoreMigrationHook() { }

    /**
     * Load data from OEM's config store.
     *
     * @return Instance of {@link MigrationData} for migrating data, null if no
     * migration is necessary.
     */
    @Nullable
    public static MigrationData load() {
        // Note: OEM's should add code to parse data from their config store format here!
        return null;
    }
}