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

Commit 878393a2 authored by Zoey Chen's avatar Zoey Chen Committed by Android (Google) Code Review
Browse files

Merge changes I80c5193c,I5e6b2169,I09a5b52a

* changes:
  [SettingsLibs] Add room database for mobile network
  [SettingsLibs] Add room DAO for mobile network
  [SettingsLibs] Add mobile network room entities
parents f636af70 2f7b9673
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -40,12 +40,6 @@ public class DataServiceUtils {
         */
        public static final String COLUMN_ID = "subId";

        /**
         * The name of the WFC provision column,
         * {@see MobileNetworkUtils#isWfcProvisionedOnDevice(int)}.
         */
        public static final String COLUMN_IS_WFC_PROVISIONED_ON_DEVICE = "isWfcProvisionedOnDevice";

        /**
         * The name of the contact discovery enabled state column,
         * {@see MobileNetworkUtils#isContactDiscoveryEnabled(Context, int)}.
+154 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.android.settingslib.mobile.dataservice;

import android.content.Context;
import android.util.Log;

import java.util.List;

import androidx.lifecycle.LiveData;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteDatabase;

@Database(entities = {SubscriptionInfoEntity.class, UiccInfoEntity.class,
        MobileNetworkInfoEntity.class}, exportSchema = false, version = 1)
public abstract class MobileNetworkDatabase extends RoomDatabase {

    public static final String TAG = "MobileNetworkDatabase";
    public static final String DATABASE_NAME = "mobilenetworksettings_db";

    public abstract SubscriptionInfoDao mSubscriptionInfoDao();

    public abstract UiccInfoDao mUiccInfoDao();

    public abstract MobileNetworkInfoDao mMobileNetworkInfoDao();

    /**
     * Create the MobileNetworkDatabase.
     *
     * @param context The context.
     * @return The MobileNetworkDatabase.
     */
    public static MobileNetworkDatabase createDatabase(Context context) {
        return Room.databaseBuilder(context,
                        MobileNetworkDatabase.class, DATABASE_NAME)
                .fallbackToDestructiveMigration()
                .enableMultiInstanceInvalidation()
                .build();
    }

    /**
     * Insert the subscription info to the SubscriptionInfoEntity table.
     *
     * @param subscriptionInfo The subscriptionInfo.
     */
    public void insertSubsInfo(SubscriptionInfoEntity... subscriptionInfo) {
        Log.d(TAG, "insertSubInfo");
        mSubscriptionInfoDao().insertSubsInfo(subscriptionInfo);
    }

    /**
     * Insert the UICC info to the UiccInfoEntity table.
     *
     * @param uiccInfoEntity The uiccInfoEntity.
     */
    public void insertUiccInfo(UiccInfoEntity... uiccInfoEntity) {
        Log.d(TAG, "insertUiccInfo");
        mUiccInfoDao().insertUiccInfo(uiccInfoEntity);
    }

    /**
     * Insert the mobileNetwork info to the MobileNetworkInfoEntity table.
     *
     * @param mobileNetworkInfoEntity The mobileNetworkInfoEntity.
     */
    public void insertMobileNetworkInfo(MobileNetworkInfoEntity... mobileNetworkInfoEntity) {
        Log.d(TAG, "insertMobileNetworkInfo");
        mMobileNetworkInfoDao().insertMobileNetworkInfo(mobileNetworkInfoEntity);
    }

    /**
     * Query available subscription infos from the SubscriptionInfoEntity table.
     */
    public LiveData<List<SubscriptionInfoEntity>> queryAvailableSubInfos() {
        return mSubscriptionInfoDao().queryAvailableSubInfos();
    }

    /**
     * Query the subscription info by the subscription ID from the SubscriptionInfoEntity
     * table.
     */
    public LiveData<SubscriptionInfoEntity> querySubInfoById(String id) {
        return mSubscriptionInfoDao().querySubInfoById(id);
    }

    /**
     * Query all mobileNetwork infos from the MobileNetworkInfoEntity
     * table.
     */
    public LiveData<List<MobileNetworkInfoEntity>> queryAllMobileNetworkInfo() {
        return mMobileNetworkInfoDao().queryAllMobileNetworkInfos();
    }

    /**
     * Query the mobileNetwork info by the subscription ID from the MobileNetworkInfoEntity
     * table.
     */
    public LiveData<MobileNetworkInfoEntity> queryMobileNetworkInfoById(String id) {
        return mMobileNetworkInfoDao().queryMobileNetworkInfoBySubId(id);
    }

    /**
     * Query all UICC infos from the UiccInfoEntity table.
     */
    public LiveData<List<UiccInfoEntity>> queryAllUiccInfo() {
        return mUiccInfoDao().queryAllUiccInfos();
    }

    /**
     * Query the UICC info by the subscription ID from the UiccInfoEntity table.
     */
    public LiveData<UiccInfoEntity> queryUiccInfoById(String id) {
        return mUiccInfoDao().queryUiccInfoById(id);
    }

    /**
     * Delete the subscriptionInfo info by the subscription ID from the SubscriptionInfoEntity
     * table.
     */
    public void deleteSubInfoBySubId(String id) {
        mSubscriptionInfoDao().deleteBySubId(id);
    }

    /**
     * Delete the mobileNetwork info by the subscription ID from the MobileNetworkInfoEntity
     * table.
     */
    public void deleteMobileNetworkInfoBySubId(String id) {
        mMobileNetworkInfoDao().deleteBySubId(id);
    }

    /**
     * Delete the UICC info by the subscription ID from the UiccInfoEntity table.
     */
    public void deleteUiccInfoBySubId(String id) {
        mUiccInfoDao().deleteBySubId(id);
    }
}
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.android.settingslib.mobile.dataservice;

import java.util.List;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

@Dao
public interface MobileNetworkInfoDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertMobileNetworkInfo(MobileNetworkInfoEntity... mobileNetworkInfo);

    @Query("SELECT * FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME + " ORDER BY "
            + DataServiceUtils.MobileNetworkInfoData.COLUMN_ID)
    LiveData<List<MobileNetworkInfoEntity>> queryAllMobileNetworkInfos();

    @Query("SELECT * FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME + " WHERE "
            + DataServiceUtils.MobileNetworkInfoData.COLUMN_ID + " = :subId")
    LiveData<MobileNetworkInfoEntity> queryMobileNetworkInfoBySubId(String subId);

    @Query("SELECT * FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME + " WHERE "
            + DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_MOBILE_DATA_ENABLED
            + " = :isMobileDataEnabled")
    LiveData<List<MobileNetworkInfoEntity>> queryMobileNetworkInfosByMobileDataStatus(
            boolean isMobileDataEnabled);

    @Query("SELECT COUNT(*) FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME)
    int count();

    @Query("DELETE FROM " + DataServiceUtils.MobileNetworkInfoData.TABLE_NAME + " WHERE "
            + DataServiceUtils.MobileNetworkInfoData.COLUMN_ID + " = :subId")
    void deleteBySubId(String subId);
}
+108 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.android.settingslib.mobile.dataservice;

import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity(tableName = DataServiceUtils.MobileNetworkInfoData.TABLE_NAME)
public class MobileNetworkInfoEntity {

    public MobileNetworkInfoEntity(@NonNull String subId, boolean isContactDiscoveryEnabled,
            boolean isContactDiscoveryVisible, boolean isMobileDataEnabled, boolean isCdmaOptions,
            boolean isGsmOptions, boolean isWorldMode, boolean shouldDisplayNetworkSelectOptions,
            boolean isTdscdmaSupported, boolean activeNetworkIsCellular,
            boolean showToggleForPhysicalSim) {
        this.subId = subId;
        this.isContactDiscoveryEnabled = isContactDiscoveryEnabled;
        this.isContactDiscoveryVisible = isContactDiscoveryVisible;
        this.isMobileDataEnabled = isMobileDataEnabled;
        this.isCdmaOptions = isCdmaOptions;
        this.isGsmOptions = isGsmOptions;
        this.isWorldMode = isWorldMode;
        this.shouldDisplayNetworkSelectOptions = shouldDisplayNetworkSelectOptions;
        this.isTdscdmaSupported = isTdscdmaSupported;
        this.activeNetworkIsCellular = activeNetworkIsCellular;
        this.showToggleForPhysicalSim = showToggleForPhysicalSim;
    }

    @PrimaryKey
    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_ID, index = true)
    @NonNull
    public String subId;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_CONTACT_DISCOVERY_ENABLED)
    public boolean isContactDiscoveryEnabled;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_CONTACT_DISCOVERY_VISIBLE)
    public boolean isContactDiscoveryVisible;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_MOBILE_DATA_ENABLED)
    public boolean isMobileDataEnabled;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_CDMA_OPTIONS)
    public boolean isCdmaOptions;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_GSM_OPTIONS)
    public boolean isGsmOptions;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_WORLD_MODE)
    public boolean isWorldMode;

    @ColumnInfo(name =
            DataServiceUtils.MobileNetworkInfoData.COLUMN_SHOULD_DISPLAY_NETWORK_SELECT_OPTIONS)
    public boolean shouldDisplayNetworkSelectOptions;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_IS_TDSCDMA_SUPPORTED)
    public boolean isTdscdmaSupported;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_ACTIVE_NETWORK_IS_CELLULAR)
    public boolean activeNetworkIsCellular;

    @ColumnInfo(name = DataServiceUtils.MobileNetworkInfoData.COLUMN_SHOW_TOGGLE_FOR_PHYSICAL_SIM)
    public boolean showToggleForPhysicalSim;

    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(" {MobileNetworkInfoEntity(subId = ")
                .append(subId)
                .append(", isContactDiscoveryEnabled = ")
                .append(isContactDiscoveryEnabled)
                .append(", isContactDiscoveryVisible = ")
                .append(isContactDiscoveryVisible)
                .append(", isMobileDataEnabled = ")
                .append(isMobileDataEnabled)
                .append(", isCdmaOptions = ")
                .append(isCdmaOptions)
                .append(", isGsmOptions = ")
                .append(isGsmOptions)
                .append(", isWorldMode = ")
                .append(isWorldMode)
                .append(", shouldDisplayNetworkSelectOptions = ")
                .append(shouldDisplayNetworkSelectOptions)
                .append(", isTdscdmaSupported = ")
                .append(isTdscdmaSupported)
                .append(", activeNetworkIsCellular = ")
                .append(activeNetworkIsCellular)
                .append(", showToggleForPhysicalSim = ")
                .append(showToggleForPhysicalSim)
                .append(")}");
        return builder.toString();
    }
}
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.android.settingslib.mobile.dataservice;

import java.util.List;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

@Dao
public interface SubscriptionInfoDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertSubsInfo(SubscriptionInfoEntity... subscriptionInfo);

    @Query("SELECT * FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME + " ORDER BY "
            + DataServiceUtils.SubscriptionInfoData.COLUMN_ID)
    LiveData<List<SubscriptionInfoEntity>> queryAvailableSubInfos();

    @Query("SELECT * FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME + " WHERE "
            + DataServiceUtils.SubscriptionInfoData.COLUMN_ID + " = :subId")
    LiveData<SubscriptionInfoEntity> querySubInfoById(String subId);

    @Query("SELECT * FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME + " WHERE "
            + DataServiceUtils.SubscriptionInfoData.COLUMN_IS_ACTIVE_SUBSCRIPTION_ID
            + " = :isActiveSubscription" + " AND "
            + DataServiceUtils.SubscriptionInfoData.COLUMN_IS_SUBSCRIPTION_VISIBLE
            + " = :isSubscriptionVisible")
    LiveData<List<SubscriptionInfoEntity>> queryActiveSubInfos(
            boolean isActiveSubscription, boolean isSubscriptionVisible);

    @Query("SELECT COUNT(*) FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME)
    int count();

    @Query("DELETE FROM " + DataServiceUtils.SubscriptionInfoData.TABLE_NAME + " WHERE "
            + DataServiceUtils.SubscriptionInfoData.COLUMN_ID + " = :id")
    void deleteBySubId(String id);

}
Loading