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

Commit 66a423e7 authored by Joshua Trask's avatar Joshua Trask
Browse files

Remove unused ChooserUtil.java

The helper methods provided by this class have been unused
since ag/13807667 (part of removing the old ChooserTargetService
functionality).

Test: http://cs/search?q=chooserutil&sq=package:android-internal
Bug: 148416928
Change-Id: I0aaaa5f597ef72097f1847a3187b335791287a60
Merged-In: I0aaaa5f597ef72097f1847a3187b335791287a60
parent a501fcb7
Loading
Loading
Loading
Loading
+0 −57
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 com.android.internal.app;

import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Utility method for common computation operations for Share sheet.
 */
public class ChooserUtil {

    private static final Charset UTF_8 = Charset.forName("UTF-8");

    /**
     * Hashes the given input based on MD5 algorithm.
     *
     * @return a string representation of the hash computation.
     */
    public static String md5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(input.getBytes(UTF_8));
            return convertBytesToHexString(md.digest());
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(e);
        }
    }

    /** Converts byte array input into an hex string. */
    private static String convertBytesToHexString(byte[] input) {
        char[] chars = new char[input.length * 2];
        for (int i = 0; i < input.length; i++) {
            byte b = input[i];
            chars[i * 2] = Character.forDigit((b >> 4) & 0xF, 16 /* radix */);
            chars[i * 2 + 1] = Character.forDigit(b & 0xF, 16 /* radix */);
        }
        return new String(chars);
    }

    private ChooserUtil() {}
}