summaryrefslogtreecommitdiffstats
path: root/chrome/common/channel_info_android.cc
blob: 11d64ed126ca726efcf7b1387cb5ee45cb0abb35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/channel_info.h"

#include "base/android/build_info.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "components/version_info/version_info.h"

namespace chrome {

std::string GetChannelString() {
  switch (GetChannel()) {
    case version_info::Channel::UNKNOWN: return "unknown";
    case version_info::Channel::CANARY: return "canary";
    case version_info::Channel::DEV: return "dev";
    case version_info::Channel::BETA: return "beta";
    case version_info::Channel::STABLE: return std::string();
  }
  NOTREACHED() << "Unknown channel " << static_cast<int>(GetChannel());
  return std::string();
}

version_info::Channel GetChannel() {
  const base::android::BuildInfo* bi = base::android::BuildInfo::GetInstance();
  DCHECK(bi && bi->package_name());

  if (!strcmp(bi->package_name(), "com.android.chrome") ||
      !strcmp(bi->package_name(), "com.chrome.work"))
    return version_info::Channel::STABLE;
  if (!strcmp(bi->package_name(), "com.chrome.beta"))
    return version_info::Channel::BETA;
  if (!strcmp(bi->package_name(), "com.chrome.dev"))
    return version_info::Channel::DEV;
  if (!strcmp(bi->package_name(), "com.chrome.canary"))
    return version_info::Channel::CANARY;

  return version_info::Channel::UNKNOWN;
}

}  // namespace chrome