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

Commit e2f9e63a authored by Fan Zhang's avatar Fan Zhang Committed by android-build-merger
Browse files

Merge "Remove duplicate classes from test/robotests" into pi-dev

am: 8b63a032

Change-Id: I2e82659b4341d3bec2ae0020216f73284c30f7f7
parents ab8d5cc0 8b63a032
Loading
Loading
Loading
Loading
+0 −110
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 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.hardware.usb;

import android.annotation.SystemService;
import android.content.Context;
import android.hardware.usb.gadget.V1_0.GadgetFunction;

import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;

/**
 * Definitions that were added to UsbManager in P.
 *
 * Copied partially from frameworks/base/core/java/android/hardware/usb/UsbManager to
 * fix issues with roboelectric during test.
 */
@SystemService(Context.USB_SERVICE)
public class UsbManagerExtras {
    public static final long NONE = 0;
    public static final long MTP = GadgetFunction.MTP;
    public static final long PTP = GadgetFunction.PTP;
    public static final long RNDIS = GadgetFunction.RNDIS;
    public static final long MIDI = GadgetFunction.MIDI;
    public static final long ACCESSORY = GadgetFunction.ACCESSORY;
    public static final long AUDIO_SOURCE = GadgetFunction.AUDIO_SOURCE;
    public static final long ADB = GadgetFunction.ADB;

    private static final long SETTABLE_FUNCTIONS = MTP | PTP | RNDIS | MIDI;

    private static final Map<String, Long> STR_MAP = new HashMap<>();

    static {
        STR_MAP.put(UsbManager.USB_FUNCTION_MTP, MTP);
        STR_MAP.put(UsbManager.USB_FUNCTION_PTP, PTP);
        STR_MAP.put(UsbManager.USB_FUNCTION_RNDIS, RNDIS);
        STR_MAP.put(UsbManager.USB_FUNCTION_MIDI, MIDI);
        STR_MAP.put(UsbManager.USB_FUNCTION_ACCESSORY, ACCESSORY);
        STR_MAP.put(UsbManager.USB_FUNCTION_AUDIO_SOURCE, AUDIO_SOURCE);
        STR_MAP.put(UsbManager.USB_FUNCTION_ADB, ADB);
    }

    /**
     * Returns whether the given functions are valid inputs to UsbManager.
     * Currently the empty functions or any of MTP, PTP, RNDIS, MIDI are accepted.
     */
    public static boolean isSettableFunctions(long functions) {
        return (~SETTABLE_FUNCTIONS & functions) == 0;
    }

    /**
     * Returns the string representation of the given functions.
     */
    public static String usbFunctionsToString(long functions) {
        StringJoiner joiner = new StringJoiner(",");
        if ((functions | MTP) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_MTP);
        }
        if ((functions | PTP) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_PTP);
        }
        if ((functions | RNDIS) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_RNDIS);
        }
        if ((functions | MIDI) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_MIDI);
        }
        if ((functions | ACCESSORY) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_ACCESSORY);
        }
        if ((functions | AUDIO_SOURCE) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_AUDIO_SOURCE);
        }
        if ((functions | ADB) != 0) {
            joiner.add(UsbManager.USB_FUNCTION_ADB);
        }
        return joiner.toString();
    }

    /**
     * Parses a string of usb functions and returns a mask of the same functions.
     */
    public static long usbFunctionsFromString(String functions) {
        if (functions == null) {
            return 0;
        }
        long ret = 0;
        for (String function : functions.split(",")) {
            if (STR_MAP.containsKey(function)) {
                ret |= STR_MAP.get(function);
            }
        }
        return ret;
    }
}
+0 −37
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 android.os;

/**
 * Duplicate class for platform SystemUpdateManager to get around Robolectric sdk problem.
 */
public class SystemUpdateManager {

    public static final String KEY_STATUS = "status";
    public static final String KEY_TITLE = "title";

    public static final int STATUS_UNKNOWN = 0;
    public static final int STATUS_IDLE = 1;
    public static final int STATUS_WAITING_DOWNLOAD = 2;
    public static final int STATUS_IN_PROGRESS = 3;
    public static final int STATUS_WAITING_INSTALL = 4;
    public static final int STATUS_WAITING_REBOOT = 5;

    public Bundle retrieveSystemUpdateInfo() {
        return null;
    }
}
+0 −112
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 android.service.notification;

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

import java.util.Objects;

/**
 * Stub implementation of framework's NotifyingApp for Robolectric tests. Otherwise Robolectric
 * throws ClassNotFoundError.
 *
 * TODO: Remove this class when Robolectric supports P
 */
public final class NotifyingApp implements Comparable<NotifyingApp> {

    private int mUid;
    private String mPkg;
    private long mLastNotified;

    public NotifyingApp() {}

    public int getUid() {
        return mUid;
    }

    /**
     * Sets the uid of the package that sent the notification. Returns self.
     */
    public NotifyingApp setUid(int mUid) {
        this.mUid = mUid;
        return this;
    }

    public String getPackage() {
        return mPkg;
    }

    /**
     * Sets the package that sent the notification. Returns self.
     */
    public NotifyingApp setPackage(@NonNull String mPkg) {
        this.mPkg = mPkg;
        return this;
    }

    public long getLastNotified() {
        return mLastNotified;
    }

    /**
     * Sets the time the notification was originally sent. Returns self.
     */
    public NotifyingApp setLastNotified(long mLastNotified) {
        this.mLastNotified = mLastNotified;
        return this;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        NotifyingApp that = (NotifyingApp) o;
        return getUid() == that.getUid()
                && getLastNotified() == that.getLastNotified()
                && Objects.equals(mPkg, that.mPkg);
    }

    @Override
    public int hashCode() {
        return Objects.hash(getUid(), mPkg, getLastNotified());
    }

    /**
     * Sorts notifying apps from newest last notified date to oldest.
     */
    @Override
    public int compareTo(NotifyingApp o) {
        if (getLastNotified() == o.getLastNotified()) {
            if (getUid() == o.getUid()) {
                return getPackage().compareTo(o.getPackage());
            }
            return Integer.compare(getUid(), o.getUid());
        }

        return -Long.compare(getLastNotified(), o.getLastNotified());
    }

    @Override
    public String toString() {
        return "NotifyingApp{"
                + "mUid=" + mUid
                + ", mPkg='" + mPkg + '\''
                + ", mLastNotified=" + mLastNotified
                + '}';
    }
}
+0 −42
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.oemlock;

/**
 * Make OemLockManager available to Robolectric.
 */
public class OemLockManager {
    public void setOemUnlockAllowedByCarrier(boolean allowed, byte[] signature) {}

    public boolean isOemUnlockAllowedByCarrier() {
        return true;
    }

    public void setOemUnlockAllowedByUser(boolean allowed) {}

    public boolean isOemUnlockAllowedByUser() {
        return false;
    }

    public boolean isOemUnlockAllowed() {
        return false;
    }

    public boolean isDeviceOemUnlocked() {
        return false;
    }
}
+0 −23
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 java.util.List;

public interface ISuggestionService {
    List<Suggestion> getSuggestions();
}
Loading