فهرست منبع

initial commit

zhipeng 3 سال پیش
کامیت
1faadfdc03
30فایلهای تغییر یافته به همراه1093 افزوده شده و 0 حذف شده
  1. 1 0
      .gitignore
  2. 30 0
      build.gradle
  3. 24 0
      proguard-rules.pro
  4. 13 0
      src/main/AndroidManifest.xml
  5. 304 0
      src/main/java/com/atmob/channelreader/AtmobApkUtil.java
  6. 95 0
      src/main/java/com/atmob/channelreader/AtmobChannelReader.java
  7. 24 0
      src/main/java/com/atmob/channelreader/ChannelInfo.java
  8. 77 0
      src/main/java/com/atmob/channelreader/ChannelReader.java
  9. 69 0
      src/main/java/com/atmob/channelreader/InternalChannelReader.java
  10. 80 0
      src/main/java/com/atmob/channelreader/Pair.java
  11. 107 0
      src/main/java/com/atmob/channelreader/PayloadReader.java
  12. 14 0
      src/main/java/com/atmob/channelreader/SignatureNotFoundException.java
  13. 30 0
      src/main/res/drawable-v24/ic_launcher_foreground.xml
  14. 170 0
      src/main/res/drawable/ic_launcher_background.xml
  15. 5 0
      src/main/res/mipmap-anydpi-v26/ic_launcher.xml
  16. 5 0
      src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
  17. BIN
      src/main/res/mipmap-hdpi/ic_launcher.webp
  18. BIN
      src/main/res/mipmap-hdpi/ic_launcher_round.webp
  19. BIN
      src/main/res/mipmap-mdpi/ic_launcher.webp
  20. BIN
      src/main/res/mipmap-mdpi/ic_launcher_round.webp
  21. BIN
      src/main/res/mipmap-xhdpi/ic_launcher.webp
  22. BIN
      src/main/res/mipmap-xhdpi/ic_launcher_round.webp
  23. BIN
      src/main/res/mipmap-xxhdpi/ic_launcher.webp
  24. BIN
      src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
  25. BIN
      src/main/res/mipmap-xxxhdpi/ic_launcher.webp
  26. BIN
      src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
  27. 16 0
      src/main/res/values-night/themes.xml
  28. 10 0
      src/main/res/values/colors.xml
  29. 3 0
      src/main/res/values/strings.xml
  30. 16 0
      src/main/res/values/themes.xml

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+/build

+ 30 - 0
build.gradle

@@ -0,0 +1,30 @@
+plugins {
+    id 'com.android.application'
+}
+
+android {
+    compileSdkVersion 32
+
+    defaultConfig {
+        applicationId "com.atmob.channelreader"
+        minSdkVersion 21
+        targetSdkVersion 32
+        versionCode 100
+        versionName "1.0.0"
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled true
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+}
+
+dependencies {
+
+}

+ 24 - 0
proguard-rules.pro

@@ -0,0 +1,24 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
+-keep class com.atmob.channelreader.ChannelReader {
+    public <methods>;
+}

+ 13 - 0
src/main/AndroidManifest.xml

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.atmob.channelreader">
+
+    <application
+        android:allowBackup="true"
+        android:icon="@mipmap/ic_launcher"
+        android:label="@string/app_name"
+        android:roundIcon="@mipmap/ic_launcher_round"
+        android:supportsRtl="true"
+        android:theme="@style/Theme.Atmobaddemo" />
+
+</manifest>

+ 304 - 0
src/main/java/com/atmob/channelreader/AtmobApkUtil.java

@@ -0,0 +1,304 @@
+package com.atmob.channelreader;
+
+import java.io.IOException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.FileChannel;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+final class AtmobApkUtil {
+    private AtmobApkUtil() {
+        super();
+    }
+
+    /**
+     * APK Signing Block Magic Code: magic “APK Sig Block 42” (16 bytes)
+     * "APK Sig Block 42" : 41 50 4B 20 53 69 67 20 42 6C 6F 63 6B 20 34 32
+     */
+    public static final long APK_SIG_BLOCK_MAGIC_HI = 0x3234206b636f6c42L; // LITTLE_ENDIAN, High
+    public static final long APK_SIG_BLOCK_MAGIC_LO = 0x20676953204b5041L; // LITTLE_ENDIAN, Low
+    private static final int APK_SIG_BLOCK_MIN_SIZE = 32;
+
+    /*
+     The v2 signature of the APK is stored as an ID-value pair with ID 0x7109871a
+     (https://source.android.com/security/apksigning/v2.html#apk-signing-block)
+      */
+    public static final int APK_SIGNATURE_SCHEME_V2_BLOCK_ID = 0x7109871a;
+
+    /**
+     * The padding in APK SIG BLOCK (V3 scheme introduced)
+     * See https://android.googlesource.com/platform/tools/apksig/+/master/src/main/java/com/android/apksig/internal/apk/ApkSigningBlockUtils.java
+     */
+    public static final int VERITY_PADDING_BLOCK_ID = 0x42726577;
+
+    public static final int ANDROID_COMMON_PAGE_ALIGNMENT_BYTES = 4096;
+
+
+    // Our Channel Block ID
+    public static final int APK_CHANNEL_BLOCK_ID = 0x71777777;
+
+    public static final String DEFAULT_CHARSET = "UTF-8";
+
+    private static final int ZIP_EOCD_REC_MIN_SIZE = 22;
+    private static final int ZIP_EOCD_REC_SIG = 0x06054b50;
+    private static final int UINT16_MAX_VALUE = 0xffff;
+    private static final int ZIP_EOCD_COMMENT_LENGTH_FIELD_OFFSET = 20;
+
+    public static long getCommentLength(final FileChannel fileChannel) throws IOException {
+        // End of central directory record (EOCD)
+        // Offset    Bytes     Description[23]
+        // 0           4       End of central directory signature = 0x06054b50
+        // 4           2       Number of this disk
+        // 6           2       Disk where central directory starts
+        // 8           2       Number of central directory records on this disk
+        // 10          2       Total number of central directory records
+        // 12          4       Size of central directory (bytes)
+        // 16          4       Offset of start of central directory, relative to start of archive
+        // 20          2       Comment length (n)
+        // 22          n       Comment
+        // For a zip with no archive comment, the
+        // end-of-central-directory record will be 22 bytes long, so
+        // we expect to find the EOCD marker 22 bytes from the end.
+
+
+        final long archiveSize = fileChannel.size();
+        if (archiveSize < ZIP_EOCD_REC_MIN_SIZE) {
+            throw new IOException("APK too small for ZIP End of Central Directory (EOCD) record");
+        }
+        // ZIP End of Central Directory (EOCD) record is located at the very end of the ZIP archive.
+        // The record can be identified by its 4-byte signature/magic which is located at the very
+        // beginning of the record. A complication is that the record is variable-length because of
+        // the comment field.
+        // The algorithm for locating the ZIP EOCD record is as follows. We search backwards from
+        // end of the buffer for the EOCD record signature. Whenever we find a signature, we check
+        // the candidate record's comment length is such that the remainder of the record takes up
+        // exactly the remaining bytes in the buffer. The search is bounded because the maximum
+        // size of the comment field is 65535 bytes because the field is an unsigned 16-bit number.
+        final long maxCommentLength = Math.min(archiveSize - ZIP_EOCD_REC_MIN_SIZE, UINT16_MAX_VALUE);
+        final long eocdWithEmptyCommentStartPosition = archiveSize - ZIP_EOCD_REC_MIN_SIZE;
+        for (int expectedCommentLength = 0; expectedCommentLength <= maxCommentLength;
+             expectedCommentLength++) {
+            final long eocdStartPos = eocdWithEmptyCommentStartPosition - expectedCommentLength;
+
+            final ByteBuffer byteBuffer = ByteBuffer.allocate(4);
+            fileChannel.position(eocdStartPos);
+            fileChannel.read(byteBuffer);
+            byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+            if (byteBuffer.getInt(0) == ZIP_EOCD_REC_SIG) {
+                final ByteBuffer commentLengthByteBuffer = ByteBuffer.allocate(2);
+                fileChannel.position(eocdStartPos + ZIP_EOCD_COMMENT_LENGTH_FIELD_OFFSET);
+                fileChannel.read(commentLengthByteBuffer);
+                commentLengthByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
+
+                final int actualCommentLength = commentLengthByteBuffer.getShort(0);
+                if (actualCommentLength == expectedCommentLength) {
+                    return actualCommentLength;
+                }
+            }
+        }
+        throw new IOException("ZIP End of Central Directory (EOCD) record not found");
+    }
+
+    public static long findCentralDirStartOffset(final FileChannel fileChannel) throws IOException {
+        return findCentralDirStartOffset(fileChannel, getCommentLength(fileChannel));
+    }
+
+    public static long findCentralDirStartOffset(final FileChannel fileChannel, final long commentLength) throws IOException {
+        // End of central directory record (EOCD)
+        // Offset    Bytes     Description[23]
+        // 0           4       End of central directory signature = 0x06054b50
+        // 4           2       Number of this disk
+        // 6           2       Disk where central directory starts
+        // 8           2       Number of central directory records on this disk
+        // 10          2       Total number of central directory records
+        // 12          4       Size of central directory (bytes)
+        // 16          4       Offset of start of central directory, relative to start of archive
+        // 20          2       Comment length (n)
+        // 22          n       Comment
+        // For a zip with no archive comment, the
+        // end-of-central-directory record will be 22 bytes long, so
+        // we expect to find the EOCD marker 22 bytes from the end.
+
+        final ByteBuffer zipCentralDirectoryStart = ByteBuffer.allocate(4);
+        zipCentralDirectoryStart.order(ByteOrder.LITTLE_ENDIAN);
+        fileChannel.position(fileChannel.size() - commentLength - 6); // 6 = 2 (Comment length) + 4 (Offset of start of central directory, relative to start of archive)
+        fileChannel.read(zipCentralDirectoryStart);
+        final long centralDirStartOffset = zipCentralDirectoryStart.getInt(0);
+        return centralDirStartOffset;
+    }
+
+    public static Pair<ByteBuffer, Long> findApkSigningBlock(
+            final FileChannel fileChannel) throws IOException, SignatureNotFoundException {
+        final long centralDirOffset = findCentralDirStartOffset(fileChannel);
+        return findApkSigningBlock(fileChannel, centralDirOffset);
+    }
+
+    public static Pair<ByteBuffer, Long> findApkSigningBlock(
+            final FileChannel fileChannel, final long centralDirOffset) throws IOException, SignatureNotFoundException {
+
+        // Find the APK Signing Block. The block immediately precedes the Central Directory.
+
+        // FORMAT:
+        // OFFSET       DATA TYPE  DESCRIPTION
+        // * @+0  bytes uint64:    size in bytes (excluding this field)
+        // * @+8  bytes payload
+        // * @-24 bytes uint64:    size in bytes (same as the one above)
+        // * @-16 bytes uint128:   magic
+
+        if (centralDirOffset < APK_SIG_BLOCK_MIN_SIZE) {
+            throw new SignatureNotFoundException(
+                    "APK too small for APK Signing Block. ZIP Central Directory offset: "
+                            + centralDirOffset);
+        }
+        // Read the magic and offset in file from the footer section of the block:
+        // * uint64:   size of block
+        // * 16 bytes: magic
+        fileChannel.position(centralDirOffset - 24);
+        final ByteBuffer footer = ByteBuffer.allocate(24);
+        fileChannel.read(footer);
+        footer.order(ByteOrder.LITTLE_ENDIAN);
+        if ((footer.getLong(8) != APK_SIG_BLOCK_MAGIC_LO)
+                || (footer.getLong(16) != APK_SIG_BLOCK_MAGIC_HI)) {
+            throw new SignatureNotFoundException(
+                    "No APK Signing Block before ZIP Central Directory");
+        }
+        // Read and compare size fields
+        final long apkSigBlockSizeInFooter = footer.getLong(0);
+        if ((apkSigBlockSizeInFooter < footer.capacity())
+                || (apkSigBlockSizeInFooter > Integer.MAX_VALUE - 8)) {
+            throw new SignatureNotFoundException(
+                    "APK Signing Block size out of range: " + apkSigBlockSizeInFooter);
+        }
+        final int totalSize = (int) (apkSigBlockSizeInFooter + 8);
+        final long apkSigBlockOffset = centralDirOffset - totalSize;
+        if (apkSigBlockOffset < 0) {
+            throw new SignatureNotFoundException(
+                    "APK Signing Block offset out of range: " + apkSigBlockOffset);
+        }
+        fileChannel.position(apkSigBlockOffset);
+        final ByteBuffer apkSigBlock = ByteBuffer.allocate(totalSize);
+        fileChannel.read(apkSigBlock);
+        apkSigBlock.order(ByteOrder.LITTLE_ENDIAN);
+        final long apkSigBlockSizeInHeader = apkSigBlock.getLong(0);
+        if (apkSigBlockSizeInHeader != apkSigBlockSizeInFooter) {
+            throw new SignatureNotFoundException(
+                    "APK Signing Block sizes in header and footer do not match: "
+                            + apkSigBlockSizeInHeader + " vs " + apkSigBlockSizeInFooter);
+        }
+        return Pair.of(apkSigBlock, apkSigBlockOffset);
+    }
+
+    public static Map<Integer, ByteBuffer> findIdValues(final ByteBuffer apkSigningBlock) throws SignatureNotFoundException {
+        checkByteOrderLittleEndian(apkSigningBlock);
+        // FORMAT:
+        // OFFSET       DATA TYPE  DESCRIPTION
+        // * @+0  bytes uint64:    size in bytes (excluding this field)
+        // * @+8  bytes pairs
+        // * @-24 bytes uint64:    size in bytes (same as the one above)
+        // * @-16 bytes uint128:   magic
+        final ByteBuffer pairs = sliceFromTo(apkSigningBlock, 8, apkSigningBlock.capacity() - 24);
+
+        final Map<Integer, ByteBuffer> idValues = new LinkedHashMap<Integer, ByteBuffer>(); // keep order
+
+        int entryCount = 0;
+        while (pairs.hasRemaining()) {
+            entryCount++;
+            if (pairs.remaining() < 8) {
+                throw new SignatureNotFoundException(
+                        "Insufficient data to read size of APK Signing Block entry #" + entryCount);
+            }
+            final long lenLong = pairs.getLong();
+            if ((lenLong < 4) || (lenLong > Integer.MAX_VALUE)) {
+                throw new SignatureNotFoundException(
+                        "APK Signing Block entry #" + entryCount
+                                + " size out of range: " + lenLong);
+            }
+            final int len = (int) lenLong;
+            final int nextEntryPos = pairs.position() + len;
+            if (len > pairs.remaining()) {
+                throw new SignatureNotFoundException(
+                        "APK Signing Block entry #" + entryCount + " size out of range: " + len
+                                + ", available: " + pairs.remaining());
+            }
+            final int id = pairs.getInt();
+            idValues.put(id, getByteBuffer(pairs, len - 4));
+
+            pairs.position(nextEntryPos);
+        }
+
+        return idValues;
+    }
+
+    /**
+     * Returns new byte buffer whose content is a shared subsequence of this buffer's content
+     * between the specified start (inclusive) and end (exclusive) positions. As opposed to
+     * {@link ByteBuffer#slice()}, the returned buffer's byte order is the same as the source
+     * buffer's byte order.
+     */
+    private static ByteBuffer sliceFromTo(final ByteBuffer source, final int start, final int end) {
+        if (start < 0) {
+            throw new IllegalArgumentException("start: " + start);
+        }
+        if (end < start) {
+            throw new IllegalArgumentException("end < start: " + end + " < " + start);
+        }
+        final int capacity = source.capacity();
+        if (end > source.capacity()) {
+            throw new IllegalArgumentException("end > capacity: " + end + " > " + capacity);
+        }
+        final int originalLimit = source.limit();
+        final int originalPosition = source.position();
+        try {
+            source.position(0);
+            source.limit(end);
+            source.position(start);
+            final ByteBuffer result = source.slice();
+            result.order(source.order());
+            return result;
+        } finally {
+            source.position(0);
+            source.limit(originalLimit);
+            source.position(originalPosition);
+        }
+    }
+
+    /**
+     * Relative <em>get</em> method for reading {@code size} number of bytes from the current
+     * position of this buffer.
+     * <p>
+     * <p>This method reads the next {@code size} bytes at this buffer's current position,
+     * returning them as a {@code ByteBuffer} with start set to 0, limit and capacity set to
+     * {@code size}, byte order set to this buffer's byte order; and then increments the position by
+     * {@code size}.
+     */
+    private static ByteBuffer getByteBuffer(final ByteBuffer source, final int size)
+            throws BufferUnderflowException {
+        if (size < 0) {
+            throw new IllegalArgumentException("size: " + size);
+        }
+        final int originalLimit = source.limit();
+        final int position = source.position();
+        final int limit = position + size;
+        if ((limit < position) || (limit > originalLimit)) {
+            throw new BufferUnderflowException();
+        }
+        source.limit(limit);
+        try {
+            final ByteBuffer result = source.slice();
+            result.order(source.order());
+            source.position(limit);
+            return result;
+        } finally {
+            source.limit(originalLimit);
+        }
+    }
+
+    private static void checkByteOrderLittleEndian(final ByteBuffer buffer) {
+        if (buffer.order() != ByteOrder.LITTLE_ENDIAN) {
+            throw new IllegalArgumentException("ByteBuffer byte order must be little endian");
+        }
+    }
+}

+ 95 - 0
src/main/java/com/atmob/channelreader/AtmobChannelReader.java

@@ -0,0 +1,95 @@
+package com.atmob.channelreader;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.text.TextUtils;
+
+import java.io.File;
+import java.util.Map;
+
+public final class AtmobChannelReader {
+    private AtmobChannelReader() {
+        super();
+    }
+
+    /**
+     * get channel
+     *
+     * @param context context
+     * @return channel, null if not fount
+     */
+    public static String getChannel(final Context context) {
+        return getChannel(context, null);
+    }
+
+    /**
+     * get channel or default
+     *
+     * @param context        context
+     * @param defaultChannel default channel
+     * @return channel, default if not fount
+     */
+    public static String getChannel(final Context context, final String defaultChannel) {
+        final ChannelInfo channelInfo = getChannelInfo(context);
+        if (channelInfo == null) {
+            return defaultChannel;
+        }
+        return channelInfo.getChannel();
+    }
+
+    /**
+     * get channel info (include channle & extraInfo)
+     *
+     * @param context context
+     * @return channel info
+     */
+    public static ChannelInfo getChannelInfo(final Context context) {
+        final String apkPath = getApkPath(context);
+        if (TextUtils.isEmpty(apkPath)) {
+            return null;
+        }
+        return InternalChannelReader.get(new File(apkPath));
+    }
+
+    /**
+     * get value by key
+     *
+     * @param context context
+     * @param key     the key you store
+     * @return value
+     */
+    public static String get(final Context context, final String key) {
+        final Map<String, String> channelMap = getChannelInfoMap(context);
+        if (channelMap == null) {
+            return null;
+        }
+        return channelMap.get(key);
+    }
+
+    /**
+     * get all channl info with map
+     *
+     * @param context context
+     * @return map
+     */
+    public static Map<String, String> getChannelInfoMap(final Context context) {
+        final String apkPath = getApkPath(context);
+        if (TextUtils.isEmpty(apkPath)) {
+            return null;
+        }
+        return InternalChannelReader.getMap(new File(apkPath));
+    }
+    
+    private static String getApkPath(final Context context) {
+        String apkPath = null;
+        try {
+            final ApplicationInfo applicationInfo = context.getApplicationInfo();
+            if (applicationInfo == null) {
+                return null;
+            }
+            apkPath = applicationInfo.sourceDir;
+        } catch (Throwable e) {
+        }
+        return apkPath;
+    }
+}

+ 24 - 0
src/main/java/com/atmob/channelreader/ChannelInfo.java

@@ -0,0 +1,24 @@
+package com.atmob.channelreader;
+
+import java.util.Map;
+
+/**
+ * Created by chentong on 17/11/2016.
+ */
+public class ChannelInfo {
+    private final String channel;
+    private final Map<String, String> extraInfo;
+
+    public ChannelInfo(final String channel, final Map<String, String> extraInfo) {
+        this.channel = channel;
+        this.extraInfo = extraInfo;
+    }
+
+    public String getChannel() {
+        return channel;
+    }
+
+    public Map<String, String> getExtraInfo() {
+        return extraInfo;
+    }
+}

+ 77 - 0
src/main/java/com/atmob/channelreader/ChannelReader.java

@@ -0,0 +1,77 @@
+package com.atmob.channelreader;
+
+import android.content.Context;
+import android.text.TextUtils;
+
+import java.util.Map;
+
+public class ChannelReader {
+
+    private static final String KEY_APP_ID = "app_id";
+
+    private static final String KEY_TG_PLATFORM_ID = "tg_platform_id";
+
+    private static final String DEFAULT_CHANNEL = "AZ";
+
+    private static final int DEFAULT_APP_ID = 0;
+
+    private static final int DEFAULT_TG_PLATFORM_ID = 0;
+
+    private static ChannelInfo channelInfo;
+
+    private static boolean initDone;
+
+    private ChannelReader() {
+    }
+
+    public static String getChannel(Context context) {
+        if (channelInfo == null) {
+            init(context);
+        }
+        return channelInfo == null ? DEFAULT_CHANNEL : TextUtils.isEmpty(channelInfo.getChannel()) ? DEFAULT_CHANNEL : channelInfo.getChannel();
+    }
+
+    public static int getAppId(Context context) {
+        String value = getExtraInfo(context, KEY_APP_ID);
+        int appId;
+        try {
+            appId = value == null ? DEFAULT_APP_ID : Integer.parseInt(value);
+        } catch (Exception ignore) {
+            appId = DEFAULT_APP_ID;
+        }
+        return appId;
+    }
+
+    public static int getTgPlatformId(Context context) {
+        String value = getExtraInfo(context, KEY_TG_PLATFORM_ID);
+        int tgPlatformId;
+        try {
+            tgPlatformId = value == null ? DEFAULT_TG_PLATFORM_ID : Integer.parseInt(value);
+        } catch (Exception e) {
+            tgPlatformId = DEFAULT_TG_PLATFORM_ID;
+        }
+        return tgPlatformId;
+    }
+
+    public static String getExtraInfo(Context context, String key) {
+        if (channelInfo == null) {
+            init(context);
+        }
+        if (channelInfo == null) {
+            return null;
+        }
+        Map<String, String> extraInfo = channelInfo.getExtraInfo();
+        if (extraInfo == null) {
+            return null;
+        }
+        return extraInfo.get(key);
+    }
+
+    private static void init(Context context) {
+        if (initDone) {
+            return;
+        }
+        channelInfo = AtmobChannelReader.getChannelInfo(context);
+        initDone = true;
+    }
+}

+ 69 - 0
src/main/java/com/atmob/channelreader/InternalChannelReader.java

@@ -0,0 +1,69 @@
+package com.atmob.channelreader;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public final class InternalChannelReader {
+    public static final String CHANNEL_KEY = "channel";
+
+    private InternalChannelReader() {
+        super();
+    }
+
+    /**
+     * easy api for get channel & extra info.<br/>
+     *
+     * @param apkFile apk file
+     * @return null if not found
+     */
+    public static ChannelInfo get(final File apkFile) {
+        final Map<String, String> result = getMap(apkFile);
+        if (result == null) {
+            return null;
+        }
+        final String channel = result.get(CHANNEL_KEY);
+        result.remove(CHANNEL_KEY);
+        return new ChannelInfo(channel, result);
+    }
+
+    /**
+     * get channel & extra info by map, use {@link InternalChannelReader#CHANNEL_KEY PayloadReader.CHANNEL_KEY} get channel
+     *
+     * @param apkFile apk file
+     * @return null if not found
+     */
+    public static Map<String, String> getMap(final File apkFile) {
+        try {
+            final String rawString = getRaw(apkFile);
+            if (rawString == null) {
+                return null;
+            }
+            final JSONObject jsonObject = new JSONObject(rawString);
+            final Iterator keys = jsonObject.keys();
+            final Map<String, String> result = new HashMap<String, String>();
+            while (keys.hasNext()) {
+                final String key = keys.next().toString();
+                result.put(key, jsonObject.getString(key));
+            }
+            return result;
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * get raw string from channel id
+     *
+     * @param apkFile apk file
+     * @return null if not found
+     */
+    public static String getRaw(final File apkFile) {
+        return PayloadReader.getString(apkFile, AtmobApkUtil.APK_CHANNEL_BLOCK_ID);
+    }
+}

+ 80 - 0
src/main/java/com/atmob/channelreader/Pair.java

@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 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.atmob.channelreader;
+
+/**
+ * Pair of two elements.
+ */
+final class Pair<A, B> {
+    private final A mFirst;
+    private final B mSecond;
+
+    private Pair(final A first, final B second) {
+        mFirst = first;
+        mSecond = second;
+    }
+
+    public static <A, B> Pair<A, B> of(final A first, final B second) {
+        return new Pair<A, B>(first, second);
+    }
+
+    public A getFirst() {
+        return mFirst;
+    }
+
+    public B getSecond() {
+        return mSecond;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((mFirst == null) ? 0 : mFirst.hashCode());
+        result = prime * result + ((mSecond == null) ? 0 : mSecond.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        @SuppressWarnings("rawtypes") final Pair other = (Pair) obj;
+        if (mFirst == null) {
+            if (other.mFirst != null) {
+                return false;
+            }
+        } else if (!mFirst.equals(other.mFirst)) {
+            return false;
+        }
+        if (mSecond == null) {
+            if (other.mSecond != null) {
+                return false;
+            }
+        } else if (!mSecond.equals(other.mSecond)) {
+            return false;
+        }
+        return true;
+    }
+}

+ 107 - 0
src/main/java/com/atmob/channelreader/PayloadReader.java

@@ -0,0 +1,107 @@
+package com.atmob.channelreader;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.Arrays;
+import java.util.Map;
+
+public final class PayloadReader {
+    private PayloadReader() {
+        super();
+    }
+
+    /**
+     * get string (UTF-8) by id
+     *
+     * @param apkFile apk file
+     * @return null if not found
+     */
+    public static String getString(final File apkFile, final int id) {
+        final byte[] bytes = PayloadReader.get(apkFile, id);
+        if (bytes == null) {
+            return null;
+        }
+        try {
+            return new String(bytes, AtmobApkUtil.DEFAULT_CHARSET);
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * get bytes by id <br/>
+     *
+     * @param apkFile apk file
+     * @param id      id
+     * @return bytes
+     */
+    public static byte[] get(final File apkFile, final int id) {
+        final Map<Integer, ByteBuffer> idValues = getAll(apkFile);
+        if (idValues == null) {
+            return null;
+        }
+        final ByteBuffer byteBuffer = idValues.get(id);
+        if (byteBuffer == null) {
+            return null;
+        }
+        return getBytes(byteBuffer);
+    }
+
+    /**
+     * get data from byteBuffer
+     *
+     * @param byteBuffer buffer
+     * @return useful data
+     */
+    private static byte[] getBytes(final ByteBuffer byteBuffer) {
+        final byte[] array = byteBuffer.array();
+        final int arrayOffset = byteBuffer.arrayOffset();
+        return Arrays.copyOfRange(array, arrayOffset + byteBuffer.position(),
+                arrayOffset + byteBuffer.limit());
+    }
+
+    /**
+     * get all custom (id, buffer) <br/>
+     * Note: get final from byteBuffer, please use {@link PayloadReader#getBytes getBytes}
+     *
+     * @param apkFile apk file
+     * @return all custom (id, buffer)
+     */
+    private static Map<Integer, ByteBuffer> getAll(final File apkFile) {
+        Map<Integer, ByteBuffer> idValues = null;
+        try {
+            RandomAccessFile randomAccessFile = null;
+            FileChannel fileChannel = null;
+            try {
+                randomAccessFile = new RandomAccessFile(apkFile, "r");
+                fileChannel = randomAccessFile.getChannel();
+                final ByteBuffer apkSigningBlock2 = AtmobApkUtil.findApkSigningBlock(fileChannel).getFirst();
+                idValues = AtmobApkUtil.findIdValues(apkSigningBlock2);
+            } catch (IOException ignore) {
+            } finally {
+                try {
+                    if (fileChannel != null) {
+                        fileChannel.close();
+                    }
+                } catch (IOException ignore) {
+                }
+                try {
+                    if (randomAccessFile != null) {
+                        randomAccessFile.close();
+                    }
+                } catch (IOException ignore) {
+                }
+            }
+        } catch (SignatureNotFoundException ignore) {
+        }
+
+        return idValues;
+    }
+
+
+}

+ 14 - 0
src/main/java/com/atmob/channelreader/SignatureNotFoundException.java

@@ -0,0 +1,14 @@
+package com.atmob.channelreader;
+
+
+public class SignatureNotFoundException extends Exception {
+    private static final long serialVersionUID = 1L;
+
+    public SignatureNotFoundException(final String message) {
+        super(message);
+    }
+
+    public SignatureNotFoundException(final String message, final Throwable cause) {
+        super(message, cause);
+    }
+}

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 30 - 0
src/main/res/drawable-v24/ic_launcher_foreground.xml


+ 170 - 0
src/main/res/drawable/ic_launcher_background.xml

@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="108dp"
+    android:height="108dp"
+    android:viewportWidth="108"
+    android:viewportHeight="108">
+    <path
+        android:fillColor="#3DDC84"
+        android:pathData="M0,0h108v108h-108z" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M9,0L9,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,0L19,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M29,0L29,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M39,0L39,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M49,0L49,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M59,0L59,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M69,0L69,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M79,0L79,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M89,0L89,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M99,0L99,108"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,9L108,9"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,19L108,19"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,29L108,29"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,39L108,39"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,49L108,49"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,59L108,59"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,69L108,69"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,79L108,79"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,89L108,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M0,99L108,99"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,29L89,29"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,39L89,39"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,49L89,49"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,59L89,59"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,69L89,69"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M19,79L89,79"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M29,19L29,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M39,19L39,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M49,19L49,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M59,19L59,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M69,19L69,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+    <path
+        android:fillColor="#00000000"
+        android:pathData="M79,19L79,89"
+        android:strokeWidth="0.8"
+        android:strokeColor="#33FFFFFF" />
+</vector>

+ 5 - 0
src/main/res/mipmap-anydpi-v26/ic_launcher.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+    <background android:drawable="@drawable/ic_launcher_background" />
+    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>

+ 5 - 0
src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+    <background android:drawable="@drawable/ic_launcher_background" />
+    <foreground android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>

BIN
src/main/res/mipmap-hdpi/ic_launcher.webp


BIN
src/main/res/mipmap-hdpi/ic_launcher_round.webp


BIN
src/main/res/mipmap-mdpi/ic_launcher.webp


BIN
src/main/res/mipmap-mdpi/ic_launcher_round.webp


BIN
src/main/res/mipmap-xhdpi/ic_launcher.webp


BIN
src/main/res/mipmap-xhdpi/ic_launcher_round.webp


BIN
src/main/res/mipmap-xxhdpi/ic_launcher.webp


BIN
src/main/res/mipmap-xxhdpi/ic_launcher_round.webp


BIN
src/main/res/mipmap-xxxhdpi/ic_launcher.webp


BIN
src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp


+ 16 - 0
src/main/res/values-night/themes.xml

@@ -0,0 +1,16 @@
+<resources xmlns:tools="http://schemas.android.com/tools">
+    <!-- Base application theme. -->
+    <style name="Theme.Atmobaddemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
+        <!-- Primary brand color. -->
+        <item name="colorPrimary">@color/purple_200</item>
+        <item name="colorPrimaryVariant">@color/purple_700</item>
+        <item name="colorOnPrimary">@color/black</item>
+        <!-- Secondary brand color. -->
+        <item name="colorSecondary">@color/teal_200</item>
+        <item name="colorSecondaryVariant">@color/teal_200</item>
+        <item name="colorOnSecondary">@color/black</item>
+        <!-- Status bar color. -->
+        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
+        <!-- Customize your theme here. -->
+    </style>
+</resources>

+ 10 - 0
src/main/res/values/colors.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <color name="purple_200">#FFBB86FC</color>
+    <color name="purple_500">#FF6200EE</color>
+    <color name="purple_700">#FF3700B3</color>
+    <color name="teal_200">#FF03DAC5</color>
+    <color name="teal_700">#FF018786</color>
+    <color name="black">#FF000000</color>
+    <color name="white">#FFFFFFFF</color>
+</resources>

+ 3 - 0
src/main/res/values/strings.xml

@@ -0,0 +1,3 @@
+<resources>
+    <string name="app_name">AtmobChannelReader</string>
+</resources>

+ 16 - 0
src/main/res/values/themes.xml

@@ -0,0 +1,16 @@
+<resources xmlns:tools="http://schemas.android.com/tools">
+    <!-- Base application theme. -->
+    <style name="Theme.Atmobaddemo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
+        <!-- Primary brand color. -->
+        <item name="colorPrimary">@color/purple_500</item>
+        <item name="colorPrimaryVariant">@color/purple_700</item>
+        <item name="colorOnPrimary">@color/white</item>
+        <!-- Secondary brand color. -->
+        <item name="colorSecondary">@color/teal_200</item>
+        <item name="colorSecondaryVariant">@color/teal_700</item>
+        <item name="colorOnSecondary">@color/black</item>
+        <!-- Status bar color. -->
+        <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
+        <!-- Customize your theme here. -->
+    </style>
+</resources>